0

I need to save a file by copying it to a .bak in a batch file.

I then need to check if my file overwrote properly the existing .bak. Simply comparing the files could not be working, as it is possible for the user to save it twice in a row with no changes.

What I already have is:

type carnet.txt > carnet.bak

or this which works too:

copy carnet.txt carnet.bak

But it does not check if the file was really overwrote.

Guillaume Chevalier
  • 9,613
  • 8
  • 51
  • 79
  • 1
    Chech for error in the operation. You ask the os to copy a file. Trust it will do their work, and if file copy fails errorlevel will be set. Check errorlevel. – MC ND Oct 29 '13 at 20:33
  • You could use `xcopy` with the `/v` option to verify the size of the file. – Okkenator Oct 30 '13 at 12:26

1 Answers1

0
 copy carnet.txt carnet.bak
 FC /b carnet.txt  carnet.bak | FIND "FC: no dif" > nul 
 IF ERRORLEVEL 1 ( echo "files are different" ) else ( echo "successful backup" )

more for FC command

npocmaka
  • 55,367
  • 18
  • 148
  • 187