Hello, please forgive me, I am new here.
What I have: Thousands of image files, named with item numbers (i.e. 12345.psd or 54321.eps)
My goal: To move images in a folder to another server, and distribute the files into numbered folders, three deep (meaning if the image is named “12345.psd”, it will go into “HI-RES IMAGES/1/12/123”. Image 54321.psd will go into "HI-RES IMAGES/5/54/543, and so on.
Images only need to go (up to) three folders deep. The many empty folders have all been created.
First, a big thanks to the other folks who have helped me get as far as I have. THANKS!
Now the code I have, which needs work (I’ll give you my issues later):
property baseFolder : missing value
on run
set baseFolder to choose folder
end run
on open theFiles
if baseFolder is missing value then set baseFolder to choose folder
repeat with oneFile in theFiles
set fileName to name of (info for oneFile)
tell fileName to set destinationfolder to (baseFolder as text) & character 1 & ":" & text 1 thru 2 & ":" & text 1 thru 3 & ":"
repeat
try
destinationfolder & fileName as alias
display dialog "file " & quote & fileName & quote & " already exists." & return ¬
& "Please choose a different name" default answer fileName buttons {"Cancel", "Overwrite", "OK"} default button 3
set {fileName, button_returned} to {text returned of result, button returned of result}
if (button_returned is "Overwrite") then
tell application "Finder" to move oneFile to folder destinationfolder with replacing
exit repeat -- File moved. Exit inner repeat.
else
tell application "Finder" to set name of oneFile to fileName -- File renamed. Do inner repeat to test new name.
end if
on error number -43 -- Catch the "File <name> wasn't found" error, but not "User Canceled".
tell application "Finder" to move oneFile to folder destinationfolder
exit repeat -- File move. Exit inner repeat.
end try
end repeat
end repeat
end open
Thank you all!
Model: 2 x 2.66 Ghz Dual-Core Intel Xeon, 4 GB 667 MHz DDR2 FB-DIMM
AppleScript: 1.10.7
Browser: Firefox 3.0.2
Operating System: Mac OS X (10.4)