Re: Deleting files from one directory that are not present in another
- From: "Pegasus \(MVP\)" <I.can@xxxxxxxxxx>
- Date: Fri, 5 Dec 2008 15:10:37 +0100
"PhilHibbs" <snarks@xxxxxxxxx> wrote in message
news:a57cc660-82ad-4f2e-bea3-cbd58ffeee9f@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm trying to sync one directory with another. I've got an xcopy
command that makes sure that files on the source are present on the
target, but I also want to delete files on the target that are not
present on the source.
Currently my command looks like this:
for /R Z:\test1 %F in (*.*) do if not exist "X:%~pnxF" del "%F"
This works fine when I run it on the command prompt directly, but
doesn't work in a cmd file. I seem to remember something about having
to double up the % but I can't remember the details, I tried this in
various places but can't make it work. Any ideas?
Phil Hibbs.
As you say, you must double your % characters when referring
to enumerating variables in batch files.
Robocopy.exe will do exactly what you want. Here is the relevant
line from its help file:
/PURGE :: delete dest files/dirs that no longer exist in source.
You can get it from
http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en.
.
- Follow-Ups:
- References:
- Prev by Date: Re: Deleting files from one directory that are not present in another
- Next by Date: Re: Magic jack
- Previous by thread: Re: Deleting files from one directory that are not present in another
- Next by thread: Re: Deleting files from one directory that are not present in another
- Index(es):
Relevant Pages
|