I need to delete all files that begin with a dot in a directory called dirA and its sub directories. Does this work?. I am afraid that I try it in real path and it will delete the good folders and files.
FOR /F "tokens=* delims=" %%X IN ('dir %1 /b /ad .*') DO del "%%X"
It needs to be safe and efficient.
delete files
Moderator: DosItHelp
Re: delete files
try this:
Code: Select all
FOR /F "tokens=* delims=" %%X IN ('dir /b .*') DO (
del /f /q "%%X"
rd /s /q "%%X"
)
Re: delete files
Greetings glob5,
You could test your code using echo, something like: (not tested)
Then examine the file my_te$t.bat to ensure proper results.
Best wishes!
You could test your code using echo, something like: (not tested)
Code: Select all
FOR /F "tokens=* delims=" %%X IN ('dir %1 /b /ad .*') DO echo del "%%X">>my_te$t.bat
Then examine the file my_te$t.bat to ensure proper results.
Best wishes!