2
I am writing a shell script using the Windows NT(ish) shell scripting language. (My computer has Windows 10.) I want to check if two text files are identical. If the files are identical, I want my script to do one thing. If the files are not identical, I want my script to do something else. The script should not pause to ask for manual entry of more data.
The "Similar Questions" list has questions about Macintosh and bash shell scripts. It also has an answer about running fc
or comp
from the command line, which provide a verbose output. Unfortunately, fc
does not return a result to %errorlevel%
, andcomp
asks for manual data entry instead of simply exiting.
I have a copy of Tim Hill's book on Windows NT shell scripting. Page 216 has the following line of code, where %D1%
and %D2%
are directories, but I do not know how to modify it to work on just a single pair of files:
for /f "tokens=*" %%I in ('fc /b %D1%\*.* %D2%\*.* ^| find /v "Comparing" ^| find /v "FC: no*"') do (set /a ERRORS+=1) & (echo %%I)
1
Is PowersShell an option? Because if it is, you might find Get-FileHash useful. I once wrote a script that removes the duplicate files from the second path; however, one can easily replace that with another command: https://superuser.com/questions/1219008/find-and-delete-duplicated-files-in-different-disks-and-directories/1219012#1219012
– flolilo – 2017-07-07T02:27:23.990@flolilolilo -- No, the rest of the script is already in the Windows NT shell scripting language. Is there a trivial way to wrap a PowerShell script to be called by a Windows NT shell script? – Jasper – 2017-07-07T02:35:48.277
What happens if you take Mr Hill's line and replace
%D1%\*.*
and%D2%\*.*
with single file names, or variables representing single file names? – Jeff Zeitlin – 2017-07-07T02:43:22.467@JeffZeitlin -- Running
fc /b a.txt b.txt | find /v "Comparing" | find /v "FC: no*"
from the command line does not produce a simple yes/no answer, but does pollute stdout. – Jasper – 2017-07-07T03:05:51.640