Page 1 of 1

Move files based on first 5 letters

PostPosted: Mon Jun 06, 2011 11:49 am
by kennedyma
Here is what I'm looking to do:

I have over 6000 folders with account documents in them, that I need to move to a different folder structure.
INPUT:
../99196-Kennedy/{Account Docs}
../FM026-Miller/{Account Docs}

OUPUT:
../99196_3078/{Account Docs}
../FM026_4440/{Account Docs}
The output folder structure is already built, as the 3078 in the output folder is a unique ID for a database we've built.
So I'm looking for a rule that will move the files based on the Account Number(99196) from the INPUT folders to the OUTPUT folders.

I know I can use the Matches criteria to get a custom value for the account number. The question I have is can I move that into another folder while having Hazel ignore everything after the account number in the new folder structure. I've tied using some apple script but it's not working well.

Apple Script:
Code: Select all
set inputFolder to choose folder with prompt "Choose input folder"
set outputFolder to choose folder with prompt "Choose output folder"
tell application "Finder"
   set allFolders to folders of inputFolder
   repeat with aFolder in allFolders
      set baseName to text 1 thru 5 of (get name of aFolder)
      set destinationFolder to (1st folder of outputFolder whose name starts with baseName)
      move files of aFolder to destinationFolder
      delete aFolder
   end repeat
end tell

Re: Move files based on first 5 letters

PostPosted: Thu Jun 09, 2011 9:53 am
by kennedyma
Just saw the post at the top. Sorry guess I can't read. Please move this to the support forum.

Re: Move files based on first 5 letters

PostPosted: Fri Jun 10, 2011 7:43 pm
by Mr_Noodle
Unfortunately, you can have Hazel dynamically determine the folder in that manner. As you've already surmised, a script is probably the best way to handle that now. In 3.0, I'm considering having a way for scripts to send values back to Hazel which can be used in subsequent patterns.

How to sort files based on file name

PostPosted: Wed Jul 13, 2011 11:13 pm
by AppleSuperlatives
Hey kennedyma - Any luck getting your AppleScript to work? I have a need for the exact same thing.