I would like to delete all files on a Windows server matching this wildcard:


In linux, I could just put an rm -rf in front of it and it would work. If I try something similar in Windows, it just gives me:

The filename, directory name, or volume label syntax is incorrect.

Any ideas about what I can do?

  • 2
    I believe a batch file with FOR loops will be needed, not any one single command will work. I needed to write one to delete every subdirectory in a directory. You batch file would be similar but you would need to test for the name of the directories and travel down each subdirectory. For a while I did look for a third party RD command to accept wild cards but if we quicker for me to write my own. However, my situation was simple. – Scott McClenning Oct 5 '10 at 18:32

Use Power Shell, which comes built-in in Win7

for example, rm -rf would translate to:

Remove-Item E:\Cache\*\*\*_ROOT\a*_SYMBOL\weekly* -force
| improve this answer | |
  • It's Windows 2008 Server, but that includes PowerShell. Isn't that handy? Thanks a lot! – Erick Robertson Oct 7 '10 at 11:26
  • What if I want to delete all folders with a certain name anywhere in the sub-tree, but starting at a certain root folder. E.g. delete all folders named TestResult within C:\Projects` and all subdirectories? Found the answer - example 4 of the Remove-Item` command explains it: get-childitem C:\Projects\* -include TestResults -recurse | remove-item – Pat Oct 11 '10 at 21:00

Share the folder. Connect to the share with linux. Use ls to generate a list of files. Open up your favorite text editor and edit the list. Add del to the front of each line. Replace all / with \ and change the path from /cache to E:\ . Add quotes around each path to protect against the ^ in the filename and change all % into %%. Copy the contents into a .bat file and execute.

| improve this answer | |

Cygwin is very useful for things like this, if you don't have a linux machine to share to. After you install it, you'll be able to execute the linux command directly on your windows folders.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.