delete files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
glob5
Posts: 34
Joined: 23 Nov 2010 00:47

delete files

#1 Post by glob5 » 19 Nov 2011 12:25

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.

renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: delete files

#2 Post by renzlo » 19 Nov 2011 15:37

try this:

Code: Select all

FOR /F "tokens=* delims=" %%X IN ('dir /b .*') DO ( 
del /f /q "%%X"
rd /s /q "%%X"
)

Ocalabob
Posts: 79
Joined: 24 Dec 2010 12:16
Location: Micanopy Florida

Re: delete files

#3 Post by Ocalabob » 20 Nov 2011 18:16

Greetings glob5,

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!

Post Reply