Solved

Delete folders in command promote with wildcards

Is there a way to Delete multiple folders, and use wildcards as well in command prompt?
For example, I have a folder with hundreds of folder, and I want to delete all of them that start with a 9.

Thanks
9 answers Last reply Best Answer
More about delete folders command promote wildcards
  1. rmdir 9* /s

    add "/q" to suppress the confirmation prompt.


    You can easily do this in Explorer as well - just sort by folder name, click on the first folder whose name starts with "9", shift-click on the last folder whose name starts with "9", and press the "Delete" key.
  2. sminlal said:
    rmdir 9* /s

    add "/q" to suppress the confirmation prompt.


    You can easily do this in Explorer as well - just sort by folder name, click on the first folder whose name starts with "9", shift-click on the last folder whose name starts with "9", and press the "Delete" key.



    Didn't work, I made a dummy folder with a bunch of folders, some starting with 9 and others with other numbers and letters.

    It did rmdir 9* /s
    and it get "The filename, directory name, or volume label syntax is incorrect".

    I was thinking about putting this in a script, so I can run it easily one 30+ computers, that is why I don't want to do in in Explorer.
  3. Best answer
    Catsrules said:
    It did rmdir 9* /s
    and it get "The filename, directory name, or volume label syntax is incorrect".
    Whoops, forgot that "rmdir" doesn't accept wildcards.

    Try this:

    for /D %f in (9*) do rmdir %f /s

    That command should work if you type in in directly at the Command Prompt window. If you want to put it into a ".bat" or a ".cmd" file, you need to double the "%" characters, as in:

    for /D %%f in (9*) do rmdir %%f /s

    As above, add "/q" to suppress the confirmation prompts.
  4. It worked!!

    So how does this fancy command work?
    I am guessing %f is a variable or something?
  5. Yeah basically the "for" command lets you execute whatever command you write after "do" multiple times, once for each file found in the "(...)" expression. The found file name is put into the "%f" variable and can be used as part of the command. "/D" tells it to look for directories - normally it will only find files.
  6. sminlal said:
    Yeah basically the "for" command lets you execute whatever command you write after "do" multiple times, once for each file found in the "(...)" expression. The found file name is put into the "%f" variable and can be used as part of the command. "/D" tells it to look for directories - normally it will only find files.



    Very cool!

    Thanks for the Education.
  7. Best answer selected by Catsrules.
  8. In these "modern times" Powershell would be the "Coolest" way to do this. :bounce:

    Change current directory to the folder where the files to be deleted exists
    (or specify in commandline "c:\MyFiles\9*")

    Option 1:
    Start Windows Powershell instead of cmd.exe and run command below:
    Remove-Item 9* -recurse -force

    Option 2:
    from Cmd/commandline..

    powershell.exe Remove-Item 9* -recurse -force

    Cheers!

    Vidar
  9. sminlal said:
    Catsrules said:
    It did rmdir 9* /s
    and it get "The filename, directory name, or volume label syntax is incorrect".
    Whoops, forgot that "rmdir" doesn't accept wildcards.

    Try this:

    for /D %f in (9*) do rmdir %f /s

    That command should work if you type in in directly at the Command Prompt window. If you want to put it into a ".bat" or a ".cmd" file, you need to double the "%" characters, as in:

    for /D %%f in (9*) do rmdir %%f /s

    As above, add "/q" to suppress the confirmation prompts.


    How and where do i put in a searchpatch for the folders?
    I have securitycameras recording videosfiles saved in folders with name of date och folder inside with time. on a specific place on my hard drive.
    For now i use a .cmd file with this commands (del /q /s D:\Users\Shares\DPFtp\hall\)
    Buit it only delete the files it selves, but not the folders.

    Is it a workaround this problem?
Ask a new question

Read More

Command Prompt Windows 7