Skip navigation

How can I Create an individual MD5 file for each folder in a main directory?

439 Views 2 Replies Latest reply: Nov 10, 2012 9:55 AM by MrHoffman RSS
MidnightJedi Calculating status...
Currently Being Moderated
Nov 9, 2012 6:25 PM

The specs for a file delivery I'm making require an individual MD5 file per folder, with the contents of that folder being inside the MD5 file. Such as:


DAY_01 (MAIN FOLDER)

A01

-(files 1-1000)

-md5 for files 1-1000

A02

-files 1001-2000

-md5 for files 1001-2000


And so on. Is there a script or program that can make those MD5 files automatically or do I hace to go and do each one individually? Thanks

Mac OS X (10.6.8)
  • Camelot Level 8 Level 8 (45,670 points)

    I don't know of any pre-existing solution to your question, but it isn't hard to write one:

     

    set theFolder to (choose folder)

     

    tell application "System Events"

              set subfolders to every folder of theFolder

     

              repeat with eachFolder in subfolders

                        set fPath to (POSIX path of eachFolder)

                        set fName to name of eachFolder

                        set md5Filename to quoted form of (fName & ".md5")

                        do shell script "cd " & quoted form of fPath & "; /sbin/md5 * > " & md5Filename

              end repeat

    end tell

     

    The idea here is that it asks for a folder to process. It then grabs a list of all the folders inside that folder (subfolders), then for each subfolder it extracts its POSIX path and the folder name, then it builds a shell command that actually goes to each folder, runs the md5 command (passing in all files), writing the output to a .md5 file named according to the folder.

  • MrHoffman Level 6 Level 6 (11,695 points)

    Your exact requirements are not something I'd expect to see a standard script for.  But for directories of files, or if you're writing a script, this is pretty easy.  (Though unlike Camelot, I would not use AppleScript for this task.  bash would likely be the local choice.)

     

    Here's a previous directory-based md5 discussion.

     

    And if changes are permissible, rsync is a common choice.

     

    The md5 cryptographic hash is known to be weak, FWIW.  It's good for testing against (or for) basic file corruptions and network transmission errors, but it's no longer appropriate for targeted attacks or security-sensitive activities.  Use a SHA hash, if this is at all involving security. 

     

    And FWIW, the openssl command-line utility provides various digests including md5 and SHA digests.

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.