How can I compare two files in a batch file?

后端 未结 3 1369
-上瘾入骨i
-上瘾入骨i 2021-02-04 05:04

How can I compare two files in a batch file, and perform an action based on whether or not they match? I\'ve tried something like:

if file1.txt NEQ file2.txt got         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 05:19

    I use the below example to build reports based on file differences:

    set %Batch_Work_Space_Dir%=folder for your batch file and temp resource files
    set file_1=name of file
    set file_2=name of file
    
    fc %file_1% %file_1%t > %Batch_Work_Space_Dir%\Are_They_Different.txt
    
    powershell -command "(Get-Content %Batch_Work_Space_Dir%\Are_They_Different.txt) | select -skip 1 | Set-Content %Batch_Work_Space_Dir%\Are_They_Different.txt"
    set /p Diff_Found=<%Batch_Work_Space_Dir%\Are_They_Different.txt
    if %Diff_Found:~0,17%" == "FC: no difference" (
      execute commands
     )
    

提交回复
热议问题