Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I want to copy a file IF it's newest with swtich /d with a message to user like ECHO New file copied.
Is there any errorlevel that can tell me whitch file that is newest?

The only way (short of finding documentation) I know of to discover errorlevels is the batch commands and analyze the results
@echo off
xcopy *.* c:\temp /switches
echo.%errorlevel%You can even get fancy and feed variables.

XCOPY returns 0 even if the date comparison fails. However, FIND returns errorlevel 0 only if there's a match. I have used the following batch file code with success:
==========================================
@echo offrem copy the file if newer and
rem send stdout to file
xcopy /d /f newfile c:\>c:\Chk.txt
if errorlevel 1 goto XERRrem trap copy error above, otherwise
rem test for the absence of "0 Files copied"
find "0 File(s) copied" c:\Chk.txt
if not errorlevel 1 goto ENDrem stuff to do goes here...
goto END
:XERR
echo Error copying file!
echo Error:%errorlevel%
:END

These are the only errorlevels and they don't include one that is date-specific as the original poster had asked (however, the 3rd party util XXCOPY might handle dates with an exit code, but I didn't look).
XCOPY ERRORLEVELS:0 - All files were copied without errors
1 - No files were found to copy (invalid source)
2 - XCOPY was terminated by Ctrl-C before copying was complete
4 - An initialization error occurred.
Such an error would generally caused by insufficient memory or disk space, or invalid drive name (invalid target) or syntax.5 - A disk-write error occurred.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |