Re: Need to delete files and folders automatically

From: *Vanguard* (no-email_at_bogus.nix)
Date: 01/29/04


Date: Thu, 29 Jan 2004 15:26:03 -0600


"anonymous@discussions.microsoft.com" said in
news:6daa01c3e6a8$c6bb1730$a501280a@phx.gbl:
> 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.

-- 


Relevant Pages

  • WinDiff.exe command line
    ... How can I envoke WinDiff.exe from the command line to compare 2 folders ... recursively (i.e. with "Include subdirectories" checked)? ...
    (microsoft.public.vsnet.enterprise.tools)
  • Success
    ... secure Windows, IIS, IE, Outlook Express ... >different upload and download folders. ... >Third party FTP software, or OpenSSH, or VPN can be used ... >1) Use a "DOS" Command Prompt for the steps below. ...
    (microsoft.public.inetserver.iis.security)
  • Re: system folders not shared?
    ... It is amazing how much can be accomplished at a command line. ... I still could not access XP's system folders. ... files would open across the network but media files would not). ... permissions to block the sharing of certain folders. ...
    (microsoft.public.windowsxp.network_web)
  • Re: Vanishing icons on Desktop and in Recycle Bin
    ... Use the command prompt ... I couldn't see a SID #. ... Both of those SID # folders should open, ... My INFO2 opens. ...
    (microsoft.public.windowsxp.help_and_support)
  • Help With [seemingly] Simple Problem
    ... I have a FreeBSD7 server box in my garage that serves the computers on my ... The box has basic non-gui install of FreeBSD7 and I access it through WinSCP ... another folder and there are same files in both folders (one I am ... Friend of mine suggested this command through ...
    (freebsd-questions)