Jump to content

Binary Data Compare Batch - [fc]


Recommended Posts

I created this some months ago to take inputs from dragged files as arguments/params to the batch file and loop through them with fc using shift, so that it would take in more than a max of 9 args :)

@echo off
SETLOCAL ENABLEEXTENSIONS
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 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

Perhaps someone else might find use for it, so I thought i'd share, and accept feedback on it

Link to comment
Share on other sites


Some general observations:

You say you created the file some months ago, but strangely it was copyrighted only this month!

You say that you have used 'SHIFT' in order to allow for more than nine arguments, but 'SHIFT' appears to not exist within the code.

Your method of determining whether any arguments were input seems a little convoluted.

You didn't explain in enough detail what the purpose of the script was:

It compares one file which when dropped with a bunch of others onto a batch file is allocated as the first parameter, (using luck), with every other file following it. i.e. compare 1 with 2, 1 with 3, 1 with 4 etc.

Link to comment
Share on other sites

Some general observations:

You say you created the file some months ago, but strangely it was copyrighted only this month!

You say that you have used 'SHIFT' in order to allow for more than nine arguments, but 'SHIFT' appears to not exist within the code.

Your method of determining whether any arguments were input seems a little convoluted.

You didn't explain in enough detail what the purpose of the script was:

It compares one file which when dropped with a bunch of others onto a batch file is allocated as the first parameter, (using luck), with every other file following it. i.e. compare 1 with 2, 1 with 3, 1 with 4 etc.

It compares one file which when dropped with a bunch of others onto a batch file is allocated as the first parameter, (using luck), with every other file following it. i.e. compare 1 with 2, 1 with 3, 1 with 4 etc.

No that is unfortunately wrong, you can determine what param or arg %1 is by making sure that you want to compare with the file that you use to drag the collection of files with, is the one you want as %1. I've tested, and it's determined by the file itself that you drag over the batch, which gets parsed as the first argument after %0. For example: If you have 3 files, file1, file2 and file3. If you select all of them, and drag these files over the batch file itself by dragging file3 to move the files over the batch file to be used as arguments, file3 will become argument %1.

I updated the year in the batch file lol. :) Batch files aren't compiled, so i'm freely able to edit that if I wish. Believe it or not, I created the script in 2011 but already had the year 2012 embedded in it anyways. It really plays no role on proof for when I created it though. For all you know I could have created this script more than a year ago (assuming the batch syntax would still be fitting for the NT version available to the user), but I still have optionality to change it to the year 9999 if I wanted lol.

My mistake though... I had a version which used SHIFT... I had it in my notepad :S but it seems I copied out this one instead. I would provide a link to where I have provided the version with, shift, but It may be against the rules, so how about I just copy the code that I have pasted on another forum here to show you the version using shift to move the input argument up by one?

Here's my first version:

@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 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

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.

I DID have a video of it in use, by the video got removed, because my Youtube account was deleted a week ago when I decided to try to delete my Google account which was linked with it. And unfortunately google deleted it along with the account.

My apologies though... I can't believe I missed that it didn't use shift. (the version of my script I posted)

If you have troubles reading it, or using the script, then just ask me though. First script is the most updated version as I found that shift was useless if I could just use the for loop to loop through all of the values in the arg list.

I know you're a good batch programmer, so no personal tension between you and me as a member, but I thought that someone may find this useful, or someone like yourself could help me improve it further.

If you don't feel like providing the advice that I so kindly looked for, even after clarifying what my idea of the kind of feedback that I wanted for this script was, then kindly do not post in this thread anymore. That's all. At least i've gotten some advice on how to check for a minimum number of input args without looping and counting each which makes my script a bit faster, but as well as a couple other little things posted by other members here.

Have a nice day

~Ace

Edited by AceInfinity
Link to comment
Share on other sites

BTW, you didn't tell me anything I didn't already know, I only mentioned the parameter allocation and how the file works because you hadn't. (It's a little pointless posting a file for others to use if they don't know what to do or what it does.)

Your method of determining whether any arguments were input still seems a little convoluted.

I know you're a good batch programmer, so no personal tension between you and me as a member, but I thought that someone may find this useful, or someone like yourself could help me improve it further.

I'm not just good I'm excellent.

Why would there be tension, you asked for feedback, and I gave some!

TBH if I were to ever come across a similar kind of problem I would be unlikely to use FC anyhow.

Link to comment
Share on other sites

BTW, you didn't tell me anything I didn't already know, I only mentioned the parameter allocation and how the file works because you hadn't. (It's a little pointless posting a file for others to use if they don't know what to do or what it does.)

Your method of determining whether any arguments were input still seems a little convoluted.

I know you're a good batch programmer, so no personal tension between you and me as a member, but I thought that someone may find this useful, or someone like yourself could help me improve it further.

I'm not just a good I'm excellent.

Why would there be tension, you asked for feedback, and I gave some!

TBH if I were to ever come across a similar kind of problem I would be unlikely to use FC anyhow.

Alright, you tell me all the bad things about my script, but you don't attempt to help me, you just point out that these things are bad. I can't claim that to be the kind of proper feedback that I was looking for to be honest.

So far you're just telling me that you're absolutely "excellent" with batch, but you can't provide some help to others other than telling them that they are doing something that may not be the best method? That shows a form of arrogance at it's lowest level in my opinion, which is not a bad thing, but if you have such knowledge, can't you attempt to utilize it to provide feedback that can help others? Feedback that can be of some use to this person? You would unlikely use FC, and my method of determining whether any arguments are inputted seems "convoluted". Okay... Why then?

You're posts don't provide any support for me, and are of zero value as of now though. It's like going to a math class, and some teacher telling you "No, that's not how you do it, try again". Well then.... "How do I do it?". That is my similar perspective here from that analogy.

Edited by AceInfinity
Link to comment
Share on other sites

You didn't ask for help you didn't ask changes, you asked for feedback!

Here's what I've already done for you:

  • Informed you that there was a discrepancy in the date you'd written in the script compared with that in which you'd stated you had written it.
  • Informed you that the main method you said you'd used wasn't in fact used at all.
  • Informed you that you could simplify a specific portion of your code.
  • Informed all readers what would happen if they ran your script thus prompting the author explanation it required.
  • Informed you that there are other ways of performing the task when faced with similar problems.

If your file works for you in your situation, and you're happy enough to post it on a public forum for others to use, then be pleased that you've done your best with it.

If I were your maths teacher I'd say that for your specific problem you got the question right. I'd then suggest that you investigate different theories or formulas to improve its efficiency and satisfy a greater diversity of working situations. I certainly wouldn't do it for you!

Please don't allow any inferiority frustration you feel to propagate further argumentative responses.

Link to comment
Share on other sites

AceInfinity, Yzöwl is providing valuable feedback.

Perhaps you meant to ask "How could this be done more efficiently?"

In that case, here is some changes I would make:

For the checking of command-line parameters, ask yourself "What do I need as input?" Your answer would be "at least 2 parameters".

So, just check for that:

if [%2] equ [] goto noArgs

You can also do away with most of the variables.

Set "original=%1"

:start
shift
if [%1] equ [] goto :eof
>>"bin_output\results.txt" fc /b %original% %1
goto start

HTH

Link to comment
Share on other sites

You can also do away with most of the variables.

Set "original=%1"

:start
shift
if [%1] equ [] goto :eof
>>"bin_output\results.txt" fc /b %original% %1
goto start

HTH

Since you have Extensions enabled you can also avoid to set the "original" variable.

This should work :unsure::


:start
>>"bin_output\results.txt" fc /b %1 %2
shift /2
if [%2] equ [] goto :eof
goto start

;)

jaclaz

Link to comment
Share on other sites

You are too kind Scr1ptW1zard, jaclaz.

As end users we really need to ask ourselves why we want to run this file. What are we looking for from it? Are we trying to find identical files, or are we trying to find files which appear the same but aren't?

What are the likely scenarios under which this type of comparison would be required?

Link to comment
Share on other sites

These last three posts are what I was looking for :) Finally some advice that I can use towards the latter if I was to create a newer version now. Thanks guys! I'll see what I can come up with, and maybe to answer this quesion Yzöwl:

As end users we really need to ask ourselves why we want to run this file. What are we looking for from it? Are we trying to find identical files, or are we trying to find files which appear the same but aren't?

What are the likely scenarios under which this type of comparison would be required?

I can do both? Provide a list of files that are identical and files that might not be?

Maybe just loop more than once, to compare not just one file to all others, but every file to each other file.

Link to comment
Share on other sites

Finally some advice that I can use towards the latter if I was to create a newer version now.

Though it may be harder to copyright this new version :whistle:

I hereby claim copyright 2012 :w00t: for the use of SHIFT /2 :ph34r:

:lol:

jaclaz

Link to comment
Share on other sites

You still don't get it AceInfinity, I provided advice, Scr1ptW1zard did the job for you and jaclaz improved on Scr1ptW1zard's work.

My questions weren't whether you could do something they were designed to lead you to the reasons why you posted the script and what your end users would use it for.

You haven't answered it, and TBH examining the scenarios whereby the file becomes useful to others is the most important thing about posting it.

What did you need it for? are many others likely to be in the same or similar situation? how would their situation differ? Are many people likely to have a single directory containing many files which may be identical in all but name and, if so, why would they want to know and what would they do with them etc.?

Take a look at the output file you get and see if there is anything in it which could be bettered for the end user, how would you change the code to do that?

Is the end user likely to need to know the differences or just whether or not there were any?

Without answering these, the only real part of the script which becomes useful to us is the portion produced by Scr1ptW1zard and improved on by jaclaz.

Link to comment
Share on other sites

Finally some advice that I can use towards the latter if I was to create a newer version now.

Though it may be harder to copyright this new version :whistle:

I hereby claim copyright 2012 :w00t: for the use of SHIFT /2 :ph34r:

:lol:

jaclaz

lol no, that copyright is more just for the looks anyway, I personally don't care if anyone uses my scripts, or modifies them in anyway, but I can provide credits with the copyright if I ever repost it, but I doubt it, i'm already making newer projects outside of batch.

You still don't get it AceInfinity' date=' I provided advice, Scr1ptW1zard did the job for you and jaclaz improved on Scr1ptW1zard's work.

My questions weren't whether you could do something they were designed to lead you to the reasons why you posted the script and what your end users would use it for.

You haven't answered it, and TBH examining the scenarios whereby the file becomes useful to others is the most important thing about posting it.

[/quote']

You're still on about this? I don't see what there is to "get" personally. This is my thread, if someone has any batch skills, which they should before attempting to run any batch script they find on the net then they can analyze it and figure it out. Otherwise there's this thread here where people can ask questions on how my script works if they are interested. I'm not here to cater to folks, and it's up to them whether they are willing to use the script or not. It's useful for comparing files, simple as that. If you're a developer, a troubleshooter, etc... Or just a curious Windows user, then you might find a use for it.

I personally made this for my own use, although decided to post it out there in case anyone else found it useful because it is universal in the way it functions.

If you just wanted to remove duplicates, then maybe MD5 hashing comparison algorithm is better. But this could be used to scan for modified Windows files or to identify malware in any case if it's been binded with an important system file and that system file has been acting up. Otherwise, again, you can choose to compare by MD5, but i'm sure the data inside the file as binary data is just as well good.

Are you interrogating me for any specific reason? Perhaps learning how this would be useful as you cannot figure it out with putting some scenarios together on your own? I'm having a hard time understanding why you can't just let me off the hook for posting this. Nobody else had much troubles with me posting here, so it can't be as bad as you claim it to be. Even if I was to explain everything, chances are there might still be questions left unanswered as I can't put together a limitless amount of probable questions and pair them off with answers in my head. No one can.

Take a look at the output file you get and see if there is anything in it which could be bettered for the end user' date=' how would you change the code to do that?[/quote']

Things can ALWAYS be improved, but is this possibly not one of the reasons to why I came here for feedback? Maybe someone else could add in something that they might find useful as an addition to my script here? Who knows. But again, this was just a friendly contribution. I never intended to work on this script for others, mainly myself, but others with permission to freely edit as they wish.

Without answering these' date=' the only real part of the script which becomes useful to us is the portion produced by Scr1ptW1zard and improved on by jaclaz. [/quote']

That doesn't make any sense to me really. But I think the reason why i'm not getting it is because I, as a human on this earth am entitled to my own opinion and point of view, and i'm just not seeing yours. You still haven't been too helpful to me in this thread after 3 posts though that you've made. You're acting like I don't have a brain here and I can't come up with suggestions on how to improve my script on my own. However, I know for a fact that i'm not going to have the same ideas as others, which is my main intension for why I created this thread.

I'm not intimidated by your modship here, i'm a decent member of many forums, and i'm entitled to my own thoughts. I just don't see you as such a friendly guy after seeing the differences in posts between you and the 2 other members in this thread, who can joke around, and provide me some constructive criticism on the current code that I have. Yours just seems more conceptual, yet you don't back it up with much of an explanation as to why you say such things so I can use your posts to better much in terms of my script.

Even if I was to think of more to add to my script that could be useful to others as you suggest, what would be the point if the current code I have now might not be ethical based on the assumptions i've made from your replies previously? You still haven't answered my questions here.

And for my main question - what WOULD you use other than fc? Seeing as how you stated that fc is NOT what you would use. I've been waiting for answers to these questions so that maybe I can at least look something up if you were to suggest anything, but I haven't been getting very far with you in this thread so far. Which is ironic, because I mainly posted to see what kind of advice you would give to me here, knowing that you have posted various batch help around the forum in the past.

Edited by AceInfinity
Link to comment
Share on other sites

Aceinfinity,

take it easy, man :).

I will try to explain to you the issues with your batch and post (nothing personal, only trying to tell you plainly what may have contributed to the present misunderstanding)

Facts:

  1. what you posted is NOT a batch file :w00t: (see below ;))
  2. it misses a simple, basic explanation of it's intended usage paradigm

Explanation:

If I remove from it the several lines of copyright related matters, it amounts to a handful of "normal", "common", batch commands (which can be made "better", as seen).

It completely misses a number of checks for "sanity" and "safety" (just imagine that you compare with it two say, DVD .iso's, and you will get a bin_output\results.txt of several Gb's :ph34r:, and probably take a bit of time to run with CPU at 100%

It cannot run from read only media (and does not provide the user for a way to choose an alternate target location), it does not check for existence of compared files, it makes no checks for runnning OS, etc., etc..

To invoke a Copyright on something, it must be something more "substantiated", IMHO, compare with:

http://www.copyright.gov/circs/circ61.pdf

All in all it amounts to a quick and dirty script to quickly do something VERY specific, like:

  1. on 2K/XP and later ONLY
  2. with relatively small files only
  3. on a Read/Write device
  4. only reliable if drag 'n drop is used

Nothing particularly "bad" about the above :), simply these things might have been specified from the beginning.

jaclaz

Link to comment
Share on other sites

Aceinfinity,

take it easy, man :).

I will try to explain to you the issues with your batch and post (nothing personal, only trying to tell you plainly what may have contributed to the present misunderstanding)

Facts:

  1. what you posted is NOT a batch file :w00t: (see below ;))
  2. it misses a simple, basic explanation of it's intended usage paradigm

Explanation:

If I remove from it the several lines of copyright related matters, it amounts to a handful of "normal", "common", batch commands (which can be made "better", as seen).

It completely misses a number of checks for "sanity" and "safety" (just imagine that you compare with it two say, DVD .iso's, and you will get a bin_output\results.txt of several Gb's :ph34r:, and probably take a bit of time to run with CPU at 100%

It cannot run from read only media (and does not provide the user for a way to choose an alternate target location), it does not check for existence of compared files, it makes no checks for runnning OS, etc., etc..

To invoke a Copyright on something, it must be something more "substantiated", IMHO, compare with:

http://www.copyright.gov/circs/circ61.pdf

All in all it amounts to a quick and dirty script to quickly do something VERY specific, like:

  1. on 2K/XP and later ONLY
  2. with relatively small files only
  3. on a Read/Write device
  4. only reliable if drag 'n drop is used

Nothing particularly "bad" about the above :), simply these things might have been specified from the beginning.

jaclaz

I agree, but I doubt anyone still uses earlier than Windows 2K/XP. I have a 95 machine, as well as a 98, and 2000 all 3 of which in working condition still that I haven't used for general or "real" computer use in years.

This kind of feedback I can respect though, now we're actually getting somewhere lol :)

I was going to iterate through the files in a directory to start off, but decided to take specific input args as files instead when I first started writing this script. I personally don't know of any other realistic built in Windows utility though that is like fc but can handle larger data though anyways. Not off the top of my head at least. Perhaps you have other suggestions on a "reference" that can be used? And i'll see what I can do to ultilize it to make a better more adaptable batch script?

I have actually created a much better version of this in Perl, although using MD5 file checksums as my comparison and narrowing the search by only comparing files of similar filesize. I was just curious one day as to what I would be limited to if I was to do the same in batch :)

Edited by AceInfinity
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...