Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Batch Script] File Binary Data Compare - (Drag & Drop / Command Line Args)
#1
Here's another batch script I just created a few minutes ago. This will use fc to compare files by their binary data with the /b flag that i've specified directly in the code. After comparing each file to the first argument as the original file in which all other arguments/parameters as files will be compared to, it creates an output text file as a log to return all of the results. If you have lots of files to compare, the buffer of the console window probably won't let you view all of the data, so it's exported to a text file instead. It may have been better to change the code to make an export of each comparison test to a new file so that the text file doesn't become too large, however I don't think anyone will be doing that, it will most likely be maybe 1-5 files.

If you want it to export to a new file everytime i'll create a new revised script if anyone wants it that way.

Important Note: The way parameters are defined, it basically uses the NTFS filesystem default from top to bottom I believe in the order that it places values into arguments that are sent (to my script in this case). Therefore you can't really choose which file goes where if you use the drag drop method, unless you open a command prompt and define each filepath manually. But that doesn't really matter as we know that if you select more than one file, WHILE DRAGGING THE GROUP OF FILES OVER MY BATCH SCRIPT THE ONE FILE THAT YOU USED TO DRAG THE GROUP OF SELECTED FILES IS PARSED AS THE FIRST ARGUMENT (%1)

This may be handy for you to know, when you want to quickly compare all other selected files to a specific file of your choice.

Code:
@echo off
title Binary File Compare - Created by AceInfinity

set i=0
set args=0 && for %%a in (%*) do set /a args+=1 && set "original=%1"
if %args% lss 2 call :noArgs
set /a args-=2

if not exist "bin_output" md "bin_output"
(
echo.----------------------------------------------------------------
echo.    Binary File Comparison Script - Created by AceInfinity
echo.              Copyright Tech.Reboot.Pro 2012
echo.----------------------------------------------------------------
echo.
) > "bin_output\results.txt"

echo Processing Binary Data...
:start
fc /b %original% %2  >> "bin_output\results.txt"
shift
set /a i+=1
if not %i% gtr %args% goto start
exit

:noArgs
echo No other input files as arguments could be found...
echo Please specify at least 2 input files to be used for comparison
echo. && pause
exit

Enjoy Smile

Don't copy and paste my script elsewhere without my permission, and give credits if you ask for my permission and you have posted this somewhere else.
Reply
#2
Wow really nice script Ace, this defidently would of taken a considerable amount of time to create. I can see myself using this in the future.

How long did this take you to make?
Reply
#3
I'm very familiar with batch, i've been programming in batch for as long as I can remember as it was the first language I ever learned, and I never stopped my scripting in batch since then. Limited language, but that doesn't mean it still can't be useful. This took me about 10 minutes.

It works like so:

Sets a variable i as 0 (this is our incerementer for when we reach the total amount of args as a value -2 (because we don't want to include %0 and param/arg %1) that we exit the endless loop and exit. For the actual loop we use fc which is a file comparer, and we send it the /b switch because now that defines that we want to compare binary data/stream.

%original% holds the value of the first file as a param/arg and we compare to the second param/arg %2 before bumping that value to the next arg in the list using shift.

If %i% is still not done with all the args as files to compare with %original% (originally %1) then we go to the start and compare the original file with the next in the args. Otherwise exit, becuase we're done.

If the args count before the loop is less than 2 then we go to :noArgs which displays that we only have 1 or no files specified, and we can't compare just 1 file to nothing, and if we have no files as input arguments then there's nothing to compare.
Reply
#4
Here's a more cleaned up version:
Code:
@echo off
title Binary File Compare - Created by AceInfinity
set /a args=0 && for %%a in (%*) do ( set /a args+=1 )
if %args% lss 2 call :noArgs

if not exist "bin_output" md "bin_output"
(
echo.----------------------------------------------------------------
echo.    Binary File Comparison Script - Created by AceInfinity
echo.              Copyright Tech.Reboot.Pro 2012
echo.----------------------------------------------------------------
echo.
) > "bin_output\results.txt"

echo Processing Binary Data...

for %%a in (%*) do (
    if not %%a==%1 (
        fc /b %1 %%a >> "bin_output\results.txt"
    )
)
exit

:noArgs
echo No other input files as arguments could be found...
echo Please specify at least 2 input files to be used for comparison
echo. && pause
exit

Should support all of the following:
  • MS-DOS 3.3x and above
  • Windows 95
  • Windows 98
  • Windows ME
  • Windows NT
  • Windows 2000
  • Windows XP
  • Windows Vista
  • Windows 7
Reply
#5
Live demonstration of what this does:
[yt]http://www.youtube.com/watch?v=TJ_1nUGYmAQ&fmt=100[/yt]
Reply
#6
Thanks for sharing the code and explain it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [TuToRiAl] Change Command Prompt Text Color [TuToRiAl] Resistance 63 28,488 01-22-2013, 09:48 PM
Last Post: Resistance
  How to Permanently, "Nuke", Erase Data Off a Hard Drive Cubs 10 3,452 12-14-2012, 04:49 AM
Last Post: JiniOnline
  Pass Generator Batch script AceInfinity 0 902 09-30-2012, 10:17 PM
Last Post: AceInfinity
  Batch tutorial goes here? fanta 3 1,514 05-22-2012, 09:25 PM
Last Post: AceInfinity
  [Batch] Trick - View Environment Variables AceInfinity 0 974 05-05-2012, 07:01 PM
Last Post: AceInfinity

Forum Jump:


Users browsing this thread: 1 Guest(s)