CRoberts Posted July 9, 2009 Posted July 9, 2009 (edited) Hi all I am building a proto-DAM database which needs to scan a folder hierarchy and create records for every folder and file. Additionally I want to record an MD5 hash for each file in order to find duplicates. I have purchased the FileManipMac plug-in which is great for determining the folders and files. My main questions is about how to traverse the hierarchy as FM doesn't seem to like recursive script calls. Perhaps it's script building technique or perhaps there's something new to FM Pro 10 Adv that I haven't utilised yet. Cheers and have a good day Craig Edited July 9, 2009 by Guest
Fenton Posted July 9, 2009 Posted July 9, 2009 (edited) I had to do something like this recently, but without the md5 (though it's a great idea). I used a straight AppleScript to do all the folders & files, then write it to text file, which I could then Import into FileMaker. I just added the md5 to it. It creates a tab delimited file. The paths are Unix paths, they do not include the drive name, but that's easy enough to add, either here or in FileMaker, if you need it. It is also possible to get the size and creation/modification dates of files. But that makes the processing many many times slower, and I had to do thousands of files, so I left it out. The "date" lines out are for a timer, to return how long it took, if you want to test on a few folders first. But it is pretty fast (the md5 added quite a bit of time, but not as bad as the size & date). You can get more info, using the unix find command, with the -ls option. But it was too much for me, and I had problems parsing it consistently. The AppleScript below writes an "EveryItem.txt" file to your Desktop. It has a timeout of 2 hours. set theFiles to "" set myFolder to choose folder with prompt "Choose the folder" set d_begin to current date tell application "Finder" set filepaths to every item of entire contents of folder myFolder as alias list with timeout of 2 * hours seconds repeat with i from 1 to count filepaths set file_path to item i of filepaths as Unicode text set unix_path to POSIX path of file_path as Unicode text if theFiles = "" then set theFiles to unix_path & tab & (do shell script "md5 -q " & quoted form of unix_path) else set theFiles to theFiles & (return & unix_path) & tab & (do shell script "md5 -q " & quoted form of unix_path) end if end repeat my write_file(theFiles) end timeout end tell set d_end to current date set d_time to d_end - d_begin on write_file(input) set inFile to (path to desktop as text) & "EveryItem.txt" try set write_This to open for access file inFile with write permission set eof of write_This to 0 --> empty file contents if needed write ((ASCII character 254) & (ASCII character 255)) to write_This -- UTF-16 BOM, write not as Unicode text write input to write_This as Unicode text on error close access write_This end try close access write_This end write_file Edited July 9, 2009 by Guest fixed fenton's issue
Fenton Posted July 9, 2009 Posted July 9, 2009 Oops. I must have forgotten to put the "/" slash in the last code tag. It caused the "Edit" bar to get wrapped as code, so I can't fix it -|
CRoberts Posted July 9, 2009 Author Posted July 9, 2009 Fenton Thanks for that. It doesn't seem to cope with folders in the hierarchy. Have you 2 minutes to help with the command to check if not a folder. Where would it go? Way back when file_path is set? Cheers C.
Fenton Posted July 9, 2009 Posted July 9, 2009 I'm not quite sure what you're asking. It does not do an md5 for a folder, but it is not an error; it just puts a tab. You choose the folder at the top of whatever hierarchy you want to get, and it gets everything inside it, no matter how deep.
Recommended Posts
This topic is 5617 days old. Please don't post here. Open a new topic instead.
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 accountSign in
Already have an account? Sign in here.
Sign In Now