How can I write a script that will save a file in the correct folder after finding it’s way to the correct folder via it’s filename?
In other words, I need to loop through numbered folders on a server (example: 10000000-1009999, 1100000-1199999. Then, a second tier of folders are inside these folders, and so on, down to the file level) until the correct location is reached.
So, a file named 1002001 would have to find it’s way down through 4 levels of folders, then save itself.
The following works to get me the name of the second tier of folders, but I CANNOT FIND OUT how to resolve the filepath correctly so the next level loop can find it. I keep getting a “Cannot Get” error. Please help! If you have any scripts to do this type of looping, I’ll gladly change it.
set item_number to 1000000 as text --test file
tell application “Finder” --fills the variable all_folders with the folders of the art archives folder
activate
set file_path to folder “Art Archives” of folder “Desktop” of folder “Klemango” of folder “Users” of startup disk of application “Finder”
set all_folders to every folder of file_path
end tell
my proper_file_name(all_folders) – pulls the first and last names from the network file path to compare to the test number
set {first_name, last_name} to result – sets the first_name and last_name variables to the result of the proper_file_name handler
my second_file_path(item_number, first_name, last_name, all_folders)
set all_folders to result
to proper_file_name(all_folders)
tell application “Finder”
repeat with current_folder in all_folders
set file_Alias to current_folder as alias
set file_Name to name of file_Alias as text
set first_name to first word of file_Name as text
set last_name to second word of file_Name
set folder_reference to {first_name, last_name}
return folder_reference
end repeat
end tell
end proper_file_name
to second_file_path(item_number, first_name, last_name, all_folders)
repeat with current_folder in all_folders
tell application "Finder"
if (item_number ≥ first_name and item_number ≤ last_name) then
set file_path to folder (first_name & "-" & last_name) of folder "Art Archives" of folder "Desktop" of folder "Klemango" of folder "Users" of startup disk of application "Finder" as text
return result
exit repeat
end if
end tell
end repeat
end second_file_path
result: “Macintosh HD:Users:Klemango:Desktop:Art Archives:1000000-1099999:”
which is correct, but I can’t go any further than this. The loop should then load the list of folders inside the above range, but I can’t get it to do that. PLEASE HELP ME, I’M MENTAL OVER THIS.