|
|
#1 |
|
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 |
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|