Need to delete files and folders automatically

G

Guest

I need to delete files and folders from a certain
directory on my server each night. Example, I have
directory D:\image, in image I use as a tempory storage
place for scanned images, I want to delete all the files
and folders in D:\image on nightly basis, but do not want
to remove the image directory.

I have tried to use the rmdir, del command in DOS to write
a batch file, but it either removes the Image directory
(can not allow because it is shared) or it will remove all
files but not the folders.

Thanks in advance for the information.
 
V

*Vanguard*

"(e-mail address removed)" said in
I need to delete files and folders from a certain
directory on my server each night. Example, I have
directory D:\image, in image I use as a tempory storage
place for scanned images, I want to delete all the files
and folders in D:\image on nightly basis, but do not want
to remove the image directory.

I have tried to use the rmdir, del command in DOS to write
a batch file, but it either removes the Image directory
(can not allow because it is shared) or it will remove all
files but not the folders.

Thanks in advance for the information.

So what's the difference between:
- Leaving the directory and deleting everything under it (files and
subdirectories)?
- Or, deleting the directory (and taking out everything under it) and
recreating that directory?

D:
cd \image
rem - Delete files:
for %%i in (*) do del "%%i" > nul
rem - Delete subdirectories:
for /d %% in (*) do rd /s /q "%%i" > nul

The doubled percent sign ("%%") is needed when running the command in a
batch file; at the command prompt, you use just one to designate a
replaceable parameter.

Make sure the parameter is quoted in the del and rd commands since it is
possible the file or subdirectories names may contain spaces.

I checked this on Windows XP but I think the for command under Windows 2000
also supports the /d option. Do "for /?" to see what options it supports on
your OS version.


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top