realityStruck
realityStruck

Reputation: 67

Checking if two files in batch are the same size

If I have the path to two files in different windows directories, how can I compare they are the same size?

%APPDATA%/profiles.ini
%USERNAME%/Desktop/profiles.ini

I want to compare they are the same file, The first thing that comes to mind is to check

  1. The files have the same name
  2. The files are the same size

If you can suggest any better ways or any improvements please say.

Upvotes: 2

Views: 759

Answers (1)

npocmaka
npocmaka

Reputation: 57252

As you already know the file names , why do you need to check if their names are the same?

not tested.

this test if the files have the same size

@echo off
set "file1=%APPDATA%/profiles.ini"
set "file2=%APPDATA%/profiles.ini"

for /f "tokens=1,2 delims=?" %%a in ("%file1%?%file2%") do (
 if %%~za equ %%~zb (
    echo equal
 ) else (
   echo not equal
 )

)

EDIT.

May be the FC command is what you need (compares content of two files).

@echo off
set "file1=%APPDATA%/profiles.ini"
set "file2=%APPDATA%/profiles.ini"
FC "%file1%" "%file2%" && ( 
   echo files are the same
   color
)||(
   echo files are different
)

Upvotes: 1

Related Questions