we do an xcopy /d of a folder with 10 files in it from source 1 to destination 1. if the file is missing or newer it works GREAT. but recently we found that the users could do a "save" or "save as" on a file in the destination 1 folder and thus create a file with a newer date than the source 1 folder with the same file name. when that happens, the xcopy /d doesn't copy the file to the destination 1 folder, and defeats the whole purpose of always wanting the source 1 folder files to over-write the destination 1 if the date timestamp is DIFFERENT regardless of newer or older in the destination 1 folder.
can someone provide an example of some dos batch that will delete all files in the destination 1 folder that don't match the date timestamp of the matching filename in the source 1 folder PLEASE?
the compare command isn't quite right, and i've google searched for hours with no luck. i'm sure others have come across this same requirements.
xcopy /d help - copy if date timestamp are different
Moderator: DosItHelp
Re: xcopy /d help - copy if date timestamp are different
Is this a single folder or a folder tree of files?
Robocopy with the /mir mirror switch will mirror a folder or tree of files.
It is destructive too, in that it removes files which don't exist in the source, so don't get the paths wrong.
Robocopy with the /mir mirror switch will mirror a folder or tree of files.
It is destructive too, in that it removes files which don't exist in the source, so don't get the paths wrong.
Re: xcopy /d help - copy if date timestamp are different
unfortunately we only have access to windows xp dos commands... not a folder tree - just a folder with 10 files in both source 1 and destination 1
Re: xcopy /d help - copy if date timestamp are different
This should delete files in the target that are not the same date and time stamp as in the source.
FWIW Robocopy can be downloaded from Microsoft for XP.
Code: Select all
@echo off
set "t=n:\target folder\"
pushd "c:\sourcefolder"
for %%a in (*.*) do (
if exist "%t%\%%a" (
for %%b in ("%t%\%%a") do (
if not "%%~ta"=="%%~tb" del "%t%\%%a"
)
)
)
FWIW Robocopy can be downloaded from Microsoft for XP.
Re: xcopy /d help - copy if date timestamp are different
thanks so much foxidrive ... i could never have come up with that...i'll test tomorrow
Re: xcopy /d help - copy if date timestamp are different
Solution we went with: XCOPY both directions. The first XCOPY uses /L (list) and puts the output to a temp file of what files don't match. Then the FOR loop deletes the files found in the temp file. Then the temp file is deleted, and the next XCOPY replaces the files that were deleted (newer on destination side than the source side which is what we didn't want to happen). The source is always the master copy, even if the destination file somehow gets saved with a newer date and timestamp.
set OutofSyncFiles=c:\Temp\OutofSyncFiles.txt
rem ** Delete any files in the C: drive folder that have been change and don't match the source Master Copy on the server
xcopy "destination\*.*" "source" /L /D /Y > "%OutofSyncFiles%"
for /f "delims=" %%i in (%OutofSyncFiles%) do del "%%i"
del "%OutofSyncFiles%"
rem ** Sync up Source Master Copy on the Server to Destination on the C: drive
xcopy "source" "destination" /D /Y /Q /Z /I
set OutofSyncFiles=c:\Temp\OutofSyncFiles.txt
rem ** Delete any files in the C: drive folder that have been change and don't match the source Master Copy on the server
xcopy "destination\*.*" "source" /L /D /Y > "%OutofSyncFiles%"
for /f "delims=" %%i in (%OutofSyncFiles%) do del "%%i"
del "%OutofSyncFiles%"
rem ** Sync up Source Master Copy on the Server to Destination on the C: drive
xcopy "source" "destination" /D /Y /Q /Z /I