I have created a batch file the runs xcopy comparing files from the server to the local machine by date. Then once those files are copied the batch file next runs a local executable the moves those files to a particular device. This works great.
I want to add the .bat file to the startup for all users, again not a problem. However, if there are no new files I do not want to run the copy command or the executable file. So what I would like to do is compare the file dates and if the dates are not 'newer - older' then just end the batch, if the date of the server file is newer then continue with the copy to the local drive.
Here is what I have so far and I'm sure I'm completely wrong.
If Exist "\\<servername>\Marketing Live\Receipt\*.*" C:\AXIDir /d
GoTo RCPTRUN
Echo "No new files to copy"
GoTo End
:RCPTRUN
xcopy /y /d "\\<servername>\Marketing Live\Receipt\*.*" C:\AXIDir
My thinking was an IF/THEN statement but I know that xcopy does not work in that fashion.
Thanks for your help.
Date Comparison for Batch file using XCOPY
Moderator: DosItHelp
Re: Date Comparison for Batch file using XCOPY
This checks if the server is accessible
It then uses the xcopy command to check for any copyable files using the /L switch.
That will print the path\filenames and the FIND command detects any "\" characters.
The && is a conditional operator that will launch on a zero errorlevel and will only run the following xcopy command when there are files to copy.
It then uses the xcopy command to check for any copyable files using the /L switch.
That will print the path\filenames and the FIND command detects any "\" characters.
The && is a conditional operator that will launch on a zero errorlevel and will only run the following xcopy command when there are files to copy.
Code: Select all
If Exist "\\<servername>\Marketing Live\Receipt\" (
xcopy /y /d /L "\\<servername>\Marketing Live\Receipt\*.*" C:\AXIDir\ |find "\" >nul && (
xcopy /y /d "\\<servername>\Marketing Live\Receipt\*.*" C:\AXIDir\
REM launch your executable here
)
)
Re: Date Comparison for Batch file using XCOPY
Thank you. That worked.