[Batch Script] File Binary Data Compare - (Drag & Drop / Command Line Args) - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Computer Support Topics (https://www.supportforums.net/forumdisplay.php?fid=4) +---- Forum: Microsoft Support (https://www.supportforums.net/forumdisplay.php?fid=5) +---- Thread: [Batch Script] File Binary Data Compare - (Drag & Drop / Command Line Args) (/showthread.php?tid=24360) |
[Batch Script] File Binary Data Compare - (Drag & Drop / Command Line Args) - AceInfinity - 01-06-2012 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 Enjoy 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. RE: [Batch Script] File Binary Data Compare - (Drag & Drop / Command Line Args) - Quizzical - 01-06-2012 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? RE: [Batch Script] File Binary Data Compare - (Drag & Drop / Command Line Args) - AceInfinity - 01-06-2012 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. RE: [Batch Script] File Binary Data Compare - (Drag & Drop / Command Line Args) - AceInfinity - 01-07-2012 Here's a more cleaned up version: Code: @echo off Should support all of the following:
RE: [Batch Script] File Binary Data Compare - (Drag & Drop / Command Line Args) - AceInfinity - 01-07-2012 Live demonstration of what this does: [yt]http://www.youtube.com/watch?v=TJ_1nUGYmAQ&fmt=100[/yt] RE: [Batch Script] File Binary Data Compare - (Drag & Drop / Command Line Args) - ISO - 01-14-2012 Thanks for sharing the code and explain it. |