Jump to content
Sign in to follow this  

Easy Get MD5 by File and Directory

Recommended Posts

I would like to start out by saying I know this isn't anything complicated, but I've noticed lately that I really am bad with completing tools, so I decided to start out easy and move on from there.

So what does this tool do?

All it does is allow the user to select a file or folder and will has the file (or files) to MD5.

The reason for making it?

I needed a quick tool to hash files and decided to make my own because, you know, why not?

Please give me advice!  I'm not that good and would love to get better!



#include <Crypt.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
Global $destFolder=0
Func main()
   Local $b_about, $b_help, $b_sd, $b_sf, $b_sdir
   GUICreate ("getMD5", 500, 100)
   $b_sdir=GUICtrlCreateButton ("Select Directory", 0, 1, 100, 20)
   $b_sf=GUICtrlCreateButton ("Select File", 100, 1, 100, 20)
   $b_sd=GUICtrlCreateButton ("Select Destination", 200, 1, 100, 20)
   $b_help=GUICtrlCreateButton ("Help", 300, 1, 100, 20)
   $b_about=GUICtrlCreateButton ("About", 400, 1, 100, 20)

   GUICtrlCreateLabel ("1. Select Destination Folder.  This will be needed to save the hashes.  Required for folder hashing, not file hashing."&@CRLF&"2. Choose whether to hash a single file or an entire folder."&@CRLF&"3. Follow the on-screen instructions", 1, 25, 498, 75)
   GUICtrlSetFont (-1, 10, 500)
   While 1
      Switch GUIGetMsg()
         Case $GUI_EVENT_CLOSE
         Case $b_sdir
            Call ("byFolder")
         Case $b_sf
            Call ("byFile")
         Case $b_sd
            $destFolder=FileSelectFolder ("Select Destination Folder", @ScriptDir)
         Case $b_help
            MsgBox (64, "Help", "This application is only supported on Windows.  -1 in the checksums file indicates a folder.  If you encounter errors, please report them to ")
         Case $b_about
            MsgBox (64, "About", "This application was created by Adam Dean.  For support, contact: ")
Func byFolder()
   local $md5, $folderopen, $files[65535], $c=1, $checksum, $foldercount=0, $sFile
   $folderopen=FileSelectFolder ("Choose Folder", @ScriptDir)
   $files=_FileListToArray ($folderopen)
   while $c <> $files[0]+1
      $checksum&=$files[$c]&" :: "&_Crypt_HashFile ( $folderopen&"\"&$files[$c], $CALG_MD5 )&@CRLF
      if @error Then
   $sFile=FileOpen ($destFolder&"\MD5_Checksum"&@MDay&@Mon&@Year&".txt",1)
   if $destfolder="0" Then
      MsgBox (48, "No destination Folder Found", "Destination Folder not found.  Please select a destination folder.")
      FileClose ($sFile)
   FileWrite ($sFile, "Total Files and Folders: "&$files[0]&@CRLF&"Total Folders found [Will not be hashed]: "&$foldercount&@CRLF&$checksum)
   MsgBox (64, "Hashing Complete", "Hashing complete.")
   FileClose ($sFile)
Func byFile()
   Local $fileOpen, $checksum
   $fileOpen=FileOpenDialog ("Select File to Hash", @ScriptDir, "All (*.*)")
   $checksum=_Crypt_HashFile ($fileOpen, $CALG_MD5 )
   MsgBox (64, "Hashing Complete", "Hashing complete.  Below is the hash of the selected file:"&@CRLF&$checksum)
   $sFile=FileOpen ($destFolder&"\MD5_Checksum"&@MDay&@Mon&@Year&".txt",1)
   if $destFolder=0 Then
      FileClose ($sFile)
   FileWrite ($sFile, "File Path: "&$fileOpen&@CRLF&"File hash: "&$checksum)
Edited by Spikeedoodles

Share this post

Link to post
Share on other sites

Not a bad start.  Nothing terribly wrong with the way you've started so far.  The only thing that stands out to me is the redundant code in your script.  While having duplcated coded in itself may not be detremental I've learned to embrace a more modular coding approach when I can.  Can you think of a way to simplify your hashing routines so that it can be utilized for either files or folders instead of having functions for both?

I also made an MD5 tool that you may be interested in reviewing just to see another way of doing things (MD5 Folder Enumarator in my signature).  Also, my script example can perform a recursive enumeration which you may be interested in seeing one way how that can be done.

Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...