Go Back   The macosxhints Forums > OS X Help Requests > AppleScript



Reply
 
Thread Tools Rate Thread Display Modes
Old 05-03-2012, 04:08 PM   #1
dcphotos
Guest
 
Posts: n/a
move files based on filename

Not sure if my first post made it but since then I have had some success with my needs. I have twenty one possible filename prefixes and I need a script to move files out of one central folder daily to folders based on those prefixes.
If I could have the script make the folders, then move the files that would be perfect. I guess I could make the folders. and example would be a file named kd-54321.jpg to be moved into a folder called kd or pld-54321.jpg to be moved into a folder called pld
the script example I found that is kind of working is

tell application "Finder"
activate
set theFolder to folder "cave" of folder "scripts" of folder "Desktop" of disk "studio11"

set chosen_folder to folder "cave" of folder "scripts" of folder "Desktop" of disk "studio11"
tell (a reference to my text item delimiters) to set {old_delim, contents} to {contents, "."}
tell application "Finder"
try
set file_list to files of chosen_folder
on error
set file_list to {}
end try
repeat with this_file in file_list
set folder_name to name of this_file
if folder_name contains "." then set folder_name to ((text items 1 thru -2 of folder_name) as string)
set new_folder to ((chosen_folder as string) & folder_name & ":")
try
get new_folder as alias
on error
make new folder at chosen_folder with properties {name:folder_name}
end try
move this_file to folder new_folder
end repeat
end tell
end tell


One problem I have with it is it names the folder the filename. I don't understand how to change it to just make the folder based on the first two characters only. Now that I think about it, I do have some three letter prefixes as well. that might also be a problem too.
any help is much appreciated.
Don
  Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 09:29 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.