Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove command in XP with empty sub directories 2

Status
Not open for further replies.
Aug 12, 2004
949
0
0
US
I have the following bat file I am running and it does not work quite right (it's a bat file that I want to schedule to run using Windows scheduler):

del D:\directory\*.* /Q /S
pause

This works great except that I have a subdirectory in this directory called the date like this:

D:\directory\021207\

This '021207' directory contains a zip file with several items in the zip file.

The data in the subdirectory deletes just fine, but the actual directory '021207' does not delete, just the data in it. The empty sub directory will not delete, that is my issue, the empty sub directory.

Anybody have any ideas?

Thanks,

Erik
 
Have you tried using the RMDIR command instead of DEL?

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
That is great, except it wants to delete the D:\directory

It wants to delete the folder and all subfolders, I do not want the top-level directory deleted, just the subfolders....

Here is what I have:

del D:\directory\*.* /Q /S
RMDIR D:\directory\ /Q /S
pause

I can't use the *.* as that does not work with the RMDIR, syntax issue, so how can I remove just the subfolders?
 
RMDIR or simply RD will remove an empty directory

rd yyy /s/q

will remove all files and sub directories and directory yyy without asking!

Therefore use with care for instance

rd c:\. /s/q

would wipe the hard drive !!!!!!!!!!!!

So what you need in your batch file is

rmdir D:\directory\*.* /Q /S

which can be reduced to

rd D:\directory\. /q /s

If you don't want to delete 'directory' use

cd D:\directory
rd . /q/s
cd ..


ignore the spurious error message
'The process cannot access the file because it is being used by another process.'

I have been known to be wrong.
The best way to thank someone who helps you is give them a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top