"PhilHibbs" <(E-Mail Removed)> wrote in message
news:a57cc660-82ad-4f2e-bea3-(E-Mail Removed)...
> 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/d...displaylang=en.