xcopy allows for the use of the parameter /d to "copy all Source files that are newer than existing Destination files" (https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true).
My question is: Is there a way to find out afterwards if any files were actually found and copied? The errorlevel returned is 0, no matter if any copy action did take place at all.
Thing is: I want to use a batch script as preparation for automated testing. It looks in some exchange directory, and copies the content to the testing environment if it finds newer files. If no newer files are found, testing would be obsolete and should be skipped.
Of course i might implement a different test step to compare if there are newer files, and please feel free to tell me if that would be best practice anyway. But to me it seemed somehow neat to cover it in one step, since I call xcopy anyway.
Thanks in advance,
Florian
FOR /f %%a IN ('XCOPY /d /l ..\* .') DO SET /a numcopied=%%a
executed before you perform you actual xcopy /d
will set numcopied
to the number of files to be copied.
Note that I used the directories ..
and .
here for testing - you'd need to substitute your dirnames.