HASHSUM.BAT v1.8 - emulate md5sum, shasum, and the like

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Michael513
Posts: 2
Joined: 01 Aug 2020 02:21

Re: HASHSUM.BAT v1.6 - emulate md5sum, shasum, and the like

#46 Post by Michael513 » 01 Aug 2020 02:32

Thanks for the batch file

I want to do something that's simpler and less complex, ideally, I want the process to be like

Code: Select all

set correctMD5=c6e160e565a0b5764cf70ed258b9ffd9
if "C:\program\config.ini" equals %correctMD5% goto :step1
if not "C:\program\config.ini" equals %correctMD5% goto :step2

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: HASHSUM.BAT v1.6 - emulate md5sum, shasum, and the like

#47 Post by dbenham » 01 Aug 2020 14:11

There is nothing complicated about it - the original post in this thread shows the basic technique. Just a few minor tweaks to get your behavior:

Code: Select all

echo %correctMD5% *C:\program\config.ini | hashsum /c /q && goto :step1 || goto :step2
Just be sure to put an asterisk before your file path, and don't use any quotes, even if there are spaces in the path. Windows automatically strips any trailing spaces from the name.


Dave Benham

Michael513
Posts: 2
Joined: 01 Aug 2020 02:21

Re: HASHSUM.BAT v1.6 - emulate md5sum, shasum, and the like

#48 Post by Michael513 » 01 Aug 2020 15:05

I just didn't know how to connect the two codes together, thank Sir Dave!

Squashman
Expert
Posts: 4484
Joined: 23 Dec 2011 13:59

Re: HASHSUM.BAT v1.6 - emulate md5sum, shasum, and the like

#49 Post by Squashman » 08 Oct 2020 08:02

Michael513 wrote:
01 Aug 2020 15:05
I just didn't know how to connect the two codes together, thank Sir Dave!
Dave, two questions.
1) When were you knighted?
2) When did you move to England?

:mrgreen:

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: HASHSUM.BAT v1.6 - emulate md5sum, shasum, and the like

#50 Post by balubeto » 17 Jan 2021 02:15

What is the latest complete and working version of this script?

How do I choose which type of hash to produce?

From the command line, what is its syntax?

Thanks

Bye

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: HASHSUM.BAT v1.6 - emulate md5sum, shasum, and the like

#51 Post by dbenham » 17 Jan 2021 06:21

The very first post of this thread always has the most recent version (currently v1.6). That version should work as long as all characters in filenames are supported by your active code page. I did not incorporate andresp's suggested changes to support all unicode charcters in file names

As for the rest - read that first post, and also the built in help.


Dave Benham

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: HASHSUM.BAT v1.6 - emulate md5sum, shasum, and the like

#52 Post by balubeto » 17 Jan 2021 09:50

dbenham wrote:
17 Jan 2021 06:21
The very first post of this thread always has the most recent version (currently v1.6). That version should work as long as all characters in filenames are supported by your active code page. I did not incorporate andresp's suggested changes to support all unicode charcters in file names

As for the rest - read that first post, and also the built in help.


Dave Benham
How do I incorporate the andresp code into the main script as well?

Thanks

Bye

Squashman
Expert
Posts: 4484
Joined: 23 Dec 2011 13:59

Re: HASHSUM.BAT v1.6 - emulate md5sum, shasum, and the like

#53 Post by Squashman » 17 Jan 2021 23:04

balubeto wrote:
17 Jan 2021 09:50
How do I incorporate the andresp code into the main script as well?

Thanks

Bye
I am going to take a wild guess and say download the code that andresp posted

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: HASHSUM.BAT v1.6 - emulate md5sum, shasum, and the like

#54 Post by balubeto » 18 Jan 2021 02:04

Squashman wrote:
17 Jan 2021 23:04
balubeto wrote:
17 Jan 2021 09:50
How do I incorporate the andresp code into the main script as well?

Thanks

Bye
I am going to take a wild guess and say download the code that andresp posted

Now, I test it.

Thanks

Bye

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: HASHSUM.BAT v1.6 - emulate md5sum, shasum, and the like

#55 Post by Compo » 18 Jan 2021 14:15

balubeto wrote:
18 Jan 2021 02:04
Now, I test it.

Thanks

Bye
Test this

Thanks

Bye

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: HASHSUM.BAT v1.7 - emulate md5sum, shasum, and the like

#56 Post by dbenham » 19 Jan 2021 13:21

I've edited the first post in this thread to version 1.7.

I adopted andresp's idea of using code page (CP) 65001 (UTF-8) to support file names that contain characters that are not in your active code page. However, the feature has not been adequately tested in my mind, so I only activate CP 65001 if you use the new /U option - and the original code page is restored upon completion.

I have a couple concerns:

1) I attempt to capture the current code page so I can reset the code page at the end. However I'm not sure that the code is robust enough to work with all languages - the CHCP output may change for different languages and break my code.

2) There are reports that CP 65001 breaks some legacy programs like FIND and MORE. So I replaced all three calls to FIND with FINDSTR /L. But I'm worried that I originally used FIND for a reason. FINDSTR is finicky/buggy, and I'm not 100% confident it will always work properly in this context.

Please report any problems with the new /U option here.


Dave Benham

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: HASHSUM.BAT v1.7 - emulate md5sum, shasum, and the like

#57 Post by Compo » 19 Jan 2021 14:29

dbenham wrote:
19 Jan 2021 13:21
I have a couple concerns:

1) I attempt to capture the current code page so I can reset the code page at the end. However I'm not sure that the code is robust enough to work with all languages - the CHCP output may change for different languages and break my code.

Dave Benham
We discussed that here, Dave, and if I remember correctly the following seemed to be the the agreed method, (modified to be directly replaceable in your code):

Code: Select all

for /f "tokens=*" %%A in ('chcp') do for %%B in (%%A) do set "chcp=%%~nB"

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: HASHSUM.BAT v1.8 - emulate md5sum, shasum, and the like

#58 Post by dbenham » 19 Jan 2021 21:32

Thanks Compo (and Carlos and the rest of the team that developed and tested that CHCP method). That helps a lot - I feel much better about capturing the active code page now.

I've updated the first post in this thread to version 1.8 with the recommended change.


Dave Benham

balubeto
Posts: 136
Joined: 08 Dec 2011 12:14

Re: HASHSUM.BAT v1.8 - emulate md5sum, shasum, and the like

#59 Post by balubeto » 20 Jan 2021 03:31

Does this script work even if the files were located in a directory on a network drive?

Thanks

Bye

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: HASHSUM.BAT v1.8 - emulate md5sum, shasum, and the like

#60 Post by dbenham » 20 Jan 2021 06:08

Easy to test - you tell me.

bye

Post Reply