Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

special delete command help

Featured Replies

can i create a command/batch that, in a folder that contains subfolders of many levels, automatically delete all the files that are named as the corresponding folder and subfolders?

For example,

In my pendrive, there're folders A and B, B has folders C and D.

I want to delete A.exe, B.exe, C.exe and D.exe in the corresponding folders, by launching a command/batch file in the root of my pendrive or in the root of A.

It's a virus.

Sure something like this

del /s a.exe,b.exe

or

for /r %G in (a.exe,b.exe) do del %G

FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]

Walks the directory tree rooted at [drive:]path, executing the FOR

statement in each directory of the tree. If no directory

specification is specified after /R then the current directory is

assumed. If set is just a single period (.) character then it

will just enumerate the directory tree.

I read it differently, therefore this will delete A\A.EXE, B\B.EXE, C\C.EXE and D\D.EXE.

@FOR %%# IN (A B C D) DO @IF EXIST %%#\%%#.EXE DEL/A/F %%#\%%#.EXE

It's my assumption that those filenames were for descriptive purposes only. I'm waiting for him to come back and say that it is not restricted to single letter files/folder names (or even names without spaces for that matter) and cannot be hardcoded as such. My guess is his intentions were that it would read the folder name, then if a file exists matching the foldername +".exe" format delete it, yada yada yada.

Is that what you were really asking for ? Does it have to be a batch file or would a VBS script be acceptable ?

Edited by MrJinje

In that case, this should suffice:

@FOR /F "TOKENS=*" %%# IN ('DIR/B/S/AD') DO @IF EXIST "%%#\%%~n#.EXE" DEL/A/F^
"%%#\%%~n#.EXE"

Copy as viewed (on two lines, the first ending with a circumflex).

  • Author
It's my assumption that those filenames were for descriptive purposes only. I'm waiting for him to come back and say that it is not restricted to single letter files/folder names (or even names without spaces for that matter) and cannot be hardcoded as such. My guess is his intentions were that it would read the folder name, then if a file exists matching the foldername +".exe" format delete it, yada yada yada.

Is that what you were really asking for ? Does it have to be a batch file or would a VBS script be acceptable ?

yes, this is exactly what i am saying..

those filenames are just for descriptive purpose.. sorry for not informing

as long as it can delete them, a vbs will do, though i prefer batch more

Thanks MrJinje

Edited by MillenX

  • Author
In that case, this should suffice:
@FOR /F "TOKENS=*" %%# IN ('DIR/B/S/AD') DO @IF EXIST "%%#\%%~n#.EXE" DEL/A/F^
 "%%#\%%~n#.EXE"

Copy as viewed (on two lines, the first ending with a circumflex).

Thanks! it works!

What does "TOKENS=*" means?

This is a way to do what you wanted as a VBS script. To use this script just Drag And Drop The Folder on the script.

Save As DelFileNameAsFolder.vbs

Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Obj
If Wscript.Arguments.Count => 1 Then
For Each Obj In WScript.Arguments
If Right(InStr(Obj,"."),5) Then
'-> Do Nothing It A File
Else
Recursive(Fso.GetFolder(Obj))
End if
Next
Else
'-> This Is For If You Dont Want To Use Drag And Drop UnComment What You Need
'-> If You Want To Hard Code A Path UnComment Below And Add Path
' Recursive(Fso.GetFolder("DRIVE\PATH_FOLDER1\FOLDER"))
'-> Or Leave The Script In The Folder And UnComment Below
' Recursive(Fso.GetFolder("."))
End If
'-> Function To Go Threw Directories And List Files
Function Recursive(Folder)
Dim File, Col
For Each File In Folder.Files
If InStr(1,File.Name,Folder.Name,1) Then Fso.DeleteFile(File.Path),True
Next
For Each Col In Folder.subFolders
Recursive(Col)
Next
End Function

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.