FC command does NOT work in a batch

February 16, 2009 at 15:35:23
Specs: Windows XP Pro
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 off

set src=\\SourceFiles\Forecast
set bkp=\\ArchiveFiles\Forecast_Backup

echo Checking if the Sales_Rep_Forecast_*.csv file(s) exists in the backup folder %bkp%

set fn=

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


See More: FC command does NOT work in a batch

Report •

February 16, 2009 at 20:15:07
Off the top of my head, try starting with this:

@echo off & setLocal EnableDelayedExpansion
And after the FC line:

echo !errorlevel!

If at first you don't succeed, you're about average.


Report •
Related Solutions

Ask Question