|I have batch file that compares a file in one folder(SourceFiles Folder) with a file in another folder (ArchiveFiles folder) and if they are different then I need to copy the file from Source folder to Archive folder.|
Souce file name is: Forecast.csv
Archive folder has many forecast files like this:
I need to compare the Forecast.csv in the source folder with the most latest file in Archive file and if they are different, I will have to copy the source file(Forecast.csv) into Archive folder with the name Forecast_20090201.csv.
When I use the FC command in the batch file to compare these two files, it is not working properly i.e. even if the files are not different, it is showing that they are different.
If I run the FC command from the command line then it works fine. The following is the summary of my commands in the batch file.
I always get the errorlevel as -1 even if the files are same.
Could some one please help me with this?
echo Checking if the Sales_Rep_Forecast_*.csv file(s) exists in the backup folder %bkp%
If Exist %bkp%\Forecast_*.csv (
echo Forecast_*.csv exists in the Backup folder: %bkp%
FOR /F %%g IN ('Dir %bkp%\Forecast_*.csv /B /O:N') DO (set fn=%%~nxg )
) ELSE (echo The Forecast file does not exist in the Backup folder: %bkp%)
If defined fn ( echo The most latest Sales_Rep_Forecast file in the Backup folder is : %fn%
echo FC /C %bkp%\%fn% %src%\Sales_Rep_Forecast.csv
FC /C %bkp%\%fn% %src%\Sales_Rep_Forecast.csv