Jump to content

command prompt


Jay_ro

Recommended Posts

Hello,

I want to delete files and folders inside a folder, using command prompt, but I want to have a prompt with y/n for each folder to delete.

The del /p command doesn't help me because it only deletes the files inside a folder. rd command is not helpful either because deletes all the folders inside my folder and it doesn't support a switch for prompting before delete.

Do you guys know a command that can delete both files and folders in a directory with prompting? Or at least a command that deletes only folders, prompting me before?

What do I need this for? I need it to delete some folders very fast. These folders inside my specific folder are very big, have lots of other files and sometimes prompts me to say that some files can't be deleted.....

Thank you

Link to comment
Share on other sites


This is a VBS script that should do what you want.

Save As DelSubFolders.vbs

Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Col, Obj, Folder
'-> Set The Current Directory The Script Is In.
'-> You Can Also Add A Direct Path To A Folder
Set Folder = Fso.GetFolder(".")
'-> Collect All The Sub Folders In The Folder
For Each Col In Folder.SubFolders
Obj = MsgBox("Did you want to delete this folder?" & vbCrLf & _
Col.Path, 4132,"Delete Folder")
'-> If Yes Is Selected Then Delete The Folder
If Obj = 6 Then Fso.DeleteFolder(Col.Path)
Next

Link to comment
Share on other sites

What about a small batch file?

If I get it right you want to delete files one by one, and then remove folders one by one, being prompted each time?

jaclaz

I use this on multiple computers. A batch file will have top be carried on a flash, is not as useful as a command.

Is there such a command at least for folder removal?

Link to comment
Share on other sites

I use this on multiple computers. A batch file will have top be carried on a flash, is not as useful as a command.

Is there such a command at least for folder removal?

Well, you can memorize a "one line" batch, but still I am not sure if you want to check if folders are empty or not.

I mean this, directly entered on command line:

FOR /F "delims=" %A  IN ('dir /b /s /A:D') DO ECHO "%A"

will list only folders "below" current path, something like this:

FOR /F "delims=" %A  IN ('dir /b /s /A:D') DO RD "%A" 2>nul

will only delete EMPTY folders (without prompting)

But you will have to re-run it for each "level".

Using this:

FOR /F "delims=" %A  IN ('dir /b /s /A:D') DO RD "%A" /S 2>nul

will prompt you, but if you say yes to deleting a higher level folder, you will be prompted for all folders in the lower levels (that do not exist anymore)

jaclaz

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...