My batch file's code is:

for /f "delims=" %%f in (7profiledeletelist.txt) do rd /s /q "%%f"

In "7profiledeletelist.txt", there are: (will be deleted)

C:\Users\1* (I tried *.* it didnt work)
C:\Users\2* (I tried *.* it didnt work)
C:\Users\3* (I tried *.* it didnt work)
C:\Users\4* (I tried *.* it didnt work)
C:\Users\5* (I tried *.* it didnt work)
C:\Users\6* (I tried *.* it didnt work)
C:\Users\7* (I tried *.* it didnt work)
C:\Users\8* (I tried *.* it didnt work)
C:\Users\9* (I tried *.* it didnt work)
C:\Users\M* (I tried *.* it didnt work)
C:\Users\T* (I tried *.* it didnt work)

But via this 7profiledeletelist.txt, bat file can not delete anything. If I remove * and If I write exact name it's working well. I want to delete all folders starting with M-T and 1 to 9 in Users. How can I change "7profiledeletelist.txt" or batch script. Is there a mistaken code in batch script? Thank you in advance :(

  • IDK if you are doing this or not but, if I were you, then I'd be testing this with an echo command instead of the rd command. It's much safer. – krowe Oct 18 '14 at 13:54
  • :) I am already testing :) There are no Folders 1 to 9. I created them for testing – serdar Oct 18 '14 at 13:58

RD doesn't support wildcards - hence why providing the full folder name works.

You could extend your script to obtain the full folder names (only the level you require), write them to another text file and use this to fuel the RD command step in your script.

| improve this answer | |
  • I found a solution, it means there is a solution what i asked here – serdar Oct 19 '14 at 16:50

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.