Delete files NOT folder

June 30, 2010 at 21:00:56
Specs: Windows XP
Hi all,

I am trying to create a batch file that scans through D:\ and delete all files, this includes scanning through all folders and deleting the files in them, leaving the folders there.

Anyone can help?

Thanks!!


See More: Delete files NOT folder

Report •


#1
June 30, 2010 at 21:08:27
pushd d:\
attrib /s -r -h -s *.*
del /s /q *.*

Report •

#2
June 30, 2010 at 22:51:55
Hi,

Thank you. Can you kindly explain what does the command do? the 2 lines?


Report •

#3
July 1, 2010 at 10:41:51
line:
pushd d:\
navigates your script to the root drive d:
(you should add a line at this point: attrib /s -r -h -s *.* to insure all files are deleted - see revised response #1)
line:
del /s /q *.*
deletes (permanently!) all files in the current directory (root), and all subdirectories recursively (ie: all subdir, all subdir in all subdirs, etc.) without querying "are you sure" each time. Please use with extreme caution and be aware of the consequenses.

Report •

Related Solutions

#4
July 1, 2010 at 11:06:31
Too bad you aren't using Linux (or other Unix family):

find starting-directory -type f -exec rm -f {}\;

Is there a port of the "find" command for Windows?


Report •

#5
July 4, 2010 at 10:03:51
Is there a port of the "find" command for Windows?
Yes, but it's hardly needed in this instance:
del /q /s /f /a d:\*


Report •


Ask Question