Folder Hashing

Discuss and share scripts and script files...
Post Reply
bluerouter
Posts: 5
Joined: 02 Dec 2010 13:54

Folder Hashing

Post by bluerouter »

Hi all,

First time poster to the forum, and hoping that someone can point me in the right direction.

I hope that I am not trying to re-invent the wheel, and that I have missed something obvious?

As part of my role I need to create hash values (MD5) of all the files within folders, and output this to a txt file. I have been using http://corz.org/windows/software/checksum/ but would rather create a script in XYplorer.

As a newbie, can this be done? Or has someone already created this. I have trawled the forums but havent come across anything yet.

Thanks in advance for any help.

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Folder Hashing

Post by highend »

You tried "hash" as the search term?

http://www.xyplorer.com/xyfc/viewtopic. ... hilit=hash

One way to do this with a script.

And instead of using <get selecteditemspathnames |> and text $result;
look into the help file for folderreport and writefile.
One of my scripts helped you out? Please donate via Paypal

bluerouter
Posts: 5
Joined: 02 Dec 2010 13:54

Re: Folder Hashing

Post by bluerouter »

Thasnks will take a look at that. I see that it is CRC32, I need to use MD5, guess it's a case of replacing the variable.

New to the scripting, so need to take some time to read, but I need to get this done quickly.

Thanks for the info.

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Folder Hashing

Post by highend »

Code: Select all

// Create hashes for all files in current folder (recursively)
   $result = "";
   $folders = folderreport("files", "r", , "r", , "|");
   foreach($file, $folders, "|") {
      if($file == "") { break; }
      $checksum = hash("md5", $file, 1);
      $result = $result . $file . " Checksum: " . $checksum . <crlf>;
   }
   writefile("<curpath>\checksum.log", $result);
Uses all files (recursively) from the current folder and writes the output to
a file named checksum.log
Last edited by highend on 01 Mar 2012 13:26, edited 1 time in total.
One of my scripts helped you out? Please donate via Paypal

bluerouter
Posts: 5
Joined: 02 Dec 2010 13:54

Re: Folder Hashing

Post by bluerouter »

Thanks, looks good.

When I get 5 minutes I just need to ouput this to a txt file rather than pop-up.

Appreciate the assist for first time user.

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Folder Hashing

Post by highend »

Edited my last post for a file instead a popup.
One of my scripts helped you out? Please donate via Paypal

bluerouter
Posts: 5
Joined: 02 Dec 2010 13:54

Re: Folder Hashing

Post by bluerouter »

Damn you're quick!

Thanks for the help, much appreciated

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Folder Hashing

Post by j_c_hallgren »

bluerouter wrote:Damn you're quick!

Thanks for the help, much appreciated
Hi and welcome to the XY forums!

That's what we pride ourselves on this forum: Being very helpful very quickly!
It's not always that speedy as it depends on time of day but it's highly unusual to not get any reply for more than a day at the very most.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

bluerouter
Posts: 5
Joined: 02 Dec 2010 13:54

Re: Folder Hashing

Post by bluerouter »

Thanks for that.

Great piece of software, I must admit I haven't used it fully yet, still getting to grips with what it can do.

Going to spend some time learning the scripting side.

:D

admin
Site Admin
Posts: 66279
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Folder Hashing

Post by admin »

Just a quick note from my holiday resort. :) I don't think this line is necessary or good within the loop:

Code: Select all

if($file == "") { break; }
folderreport() never returns empty elements IF it returns anything (which it does not when the folder is empty, or if certain flags are passed which filter the return). So I'd rather check for empty folders like this:

Code: Select all

// Create hashes for all files in current folder (recursively)
  $result = "";
  $folders = folderreport("files", "r", , "r", , "|");
  if (strlen($folders)) {
    foreach($file, $folders, "|") {
      $checksum = hash("md5", $file, 1);
      $result = $result . $file . " Checksum: " . $checksum . <crlf>;
    }
    writefile("<curpath>\checksum.log", $result);
  } else {
    msg "Folder empty."
  }

Post Reply