How can I compare two files in a batch file?

后端 未结 3 1370
-上瘾入骨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:20

    It seems like the COMP program is actually fairly easy to use. See this question on Yahoo answers.

    Note that running comp /? will print the help text for the program (as does specifying the /? argument with any native Windows command line program). This outputs the same text you see in the answer of the question linked above.

    Content from the Yahoo Answer:

    C:\>comp /? 
    Compares the contents of two files or sets of files. 
    
    COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C] [/OFF[LINE]] 
    
    data1 Specifies location and name(s) of first file(s) to compare. 
    data2 Specifies location and name(s) of second files to compare. 
    /D Displays differences in decimal format. 
    /A Displays differences in ASCII characters. 
    /L Displays line numbers for differences. 
    /N=number Compares only the first specified number of lines in each file. 
    /C Disregards case of ASCII letters when comparing files. 
    /OFF[LINE] Do not skip files with offline attribute set. 
    
    To compare sets of files, use wildcards in data1 and data2 parameters.
    

提交回复
热议问题