Re: Deleting files from one directory that are not present in another

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"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.


.



Relevant Pages

  • Re: War Celebrations
    ... If the factories cannot be stopped any other way, I have no problem in the ... morality of blowing up estates full of factory workers who spend their ... are a legitimate target, but I suspect that usually the workers from diverse ... Command were not entirely those under the command of Adolf ...
    (uk.legal)
  • Re: War Celebrations
    ... are a legitimate target, but I suspect that usually the workers from diverse ... As the winter of 1943 approached, the forces aligned against Bomber ... Command were not entirely those under the command of Adolf ... Lindemann's minute on area bombing, ...
    (uk.legal)
  • Re: U.S. Navy taking on pirates, sort of
    ... Open-ended bureaucratic blather accompanied by actual ... little or no radio communications except in the "command" a/c. ... waving a sign with the target bearing boldly chalked (and woe to he who ...
    (sci.military.naval)
  • Re: Remote debugging
    ... msvcmon.exe -anyuseran error box pops up with:"Invalid command line ... saying:msvcmon.exe does not seem to be running on the target ... This works only when I copy the debugged application from host ... I want to debug from my notebook (XP Pro) as host to target ...
    (microsoft.public.windowsxp.embedded)
  • Re: Suggestion Question
    ... So if the target is told "I suggest you give 1gp to every ... command spoken to you in elven you follow that command." ... ended influence over a victim, but to have the victim perform a ... Elvish" is open-ended and nonspecific, ...
    (rec.games.frp.dnd)