did you see my suggestion (post #5) ?
Nice piece of script.
Your shell script commands won’t bog down like Finder scripting often does when it tries to handle 1000+ files.
Long term, that’s the way to fly, but spoma’s learning the basics.
Still, this can’t hurt: Technical Note TN2065 do shell script in AppleScript
StefanK - I completely apologize. I never even noticed your post. I am not sure how I missed it. I will take a look at it in a little while and see how you did it in comparison to what I did. In some ways it is good because it forced me to learn some of the basics of AppleScript and I understand what I did. Hopefully, this will give me a little more background to help me understand what you did. Thanks for the help.
I added the if statements into my script and cleaned up a couple of places. Everything appears to work. Does anyone see any flaws in the way I did this. As a test I moved 500 pictures and they moved fairly quickly (seconds), so I am happy with performance.
Thanks for all the help.
set SourceFolder to "Macintosh HD:Users:UserName:Downloads:Pictures to Be Moved:"
set DestFolder to "Macintosh HD:Shares:Pictures:DIGITALPICS:"
tell application "Finder"
set lst to name of every item in folder SourceFolder
repeat with i from 1 to count lst
set theMonth to text 1 thru 2 of lst's item i
set theDay to text 3 thru 4 of lst's item i
set theYear to text 8 thru 5 of lst's item i
set the_FullFile to SourceFolder & lst's item i
if (theMonth = "01") and (theYear ≥ "2014") then
move file the_FullFile to DestFolder & theYear & ":" & theMonth & "Jan" & theYear with replacing
else if (theMonth = "02") and (theYear ≥ "2014") then
move file the_FullFile to DestFolder & theYear & ":" & theMonth & "Feb" & theYear with replacing
else if (theMonth = "03") and (theYear ≥ "2014") then
move file the_FullFile to DestFolder & theYear & ":" & theMonth & "Mar" & theYear with replacing
else if (theMonth = "04") and (theYear ≥ "2014") then
move file the_FullFile to DestFolder & theYear & ":" & theMonth & "Apr" & theYear with replacing
else if (theMonth = "05") and (theYear ≥ "2014") then
move file the_FullFile to DestFolder & theYear & ":" & theMonth & "May" & theYear with replacing
else if (theMonth = "06") and (theYear ≥ "2014") then
move file the_FullFile to DestFolder & theYear & ":" & theMonth & "Jun" & theYear with replacing
else if (theMonth = "07") and (theYear ≥ "2014") then
move file the_FullFile to DestFolder & theYear & ":" & theMonth & "Jul" & theYear with replacing
else if (theMonth = "08") and (theYear ≥ "2014") then
move file the_FullFile to DestFolder & theYear & ":" & theMonth & "Aug" & theYear with replacing
else if (theMonth = "09") and (theYear ≥ "2014") then
move file the_FullFile to DestFolder & theYear & ":" & theMonth & "Sep" & theYear with replacing
else if (theMonth = "10") and (theYear ≥ "2014") then
move file the_FullFile to DestFolder & theYear & ":" & theMonth & "Oct" & theYear with replacing
else if (theMonth = "11") and (theYear ≥ "2014") then
move file the_FullFile to DestFolder & theYear & ":" & theMonth & "Nov" & theYear with replacing
else if (theMonth = "12") and (theYear ≥ "2014") then
move file the_FullFile to DestFolder & theYear & ":" & theMonth & "Dec" & theYear with replacing
end if
end repeat
end tell
StefanK - I am still going to take a look at your script and compare to what I did. I took a quick look and yours was completely different so it will take me a little time to understand what each of the lines were doing. But, it is a great way for me to learn. Thanks.
StefanK - I was looking over your script and I have a couple of questions.
-
Is the use of shell scripting for moving files more efficient than using the Finder move that I used. I would guess yes since you used it but was just curious. I could easily switching over to using the shell script commands. I have never used ditto before but did a man on it and it seems pretty interesting.
-
Can you explain this line to me?
set folderName to theMonth & item (theMonth as integer) of monthAbbreviations & theyear
From what I can tell this line would allow me to get rid of all of the ‘if’ statements because of the use of monthAbbreviations. How does the mapping occur between theMonth and monthAbbreviations. Does it just go in order and they are 1,2,3, etc… ?
Thanks for all the help.
the main purpose of using ditto is that it is able to create intermediate directories automatically.
So you don’t have to create the folders manually, the script will do it.
Shell scripts especially for copying files are more efficient then scripting the Finder
this is the line where the folder name (e.g. 02FEB2104) is created. From your first post I assumed that the date string format is 02042014 for February 4, 2014. So the month index (2) picks the second item of the monthAbbrev list which is FEB
Thanks StefanK
I wanted to make sure this was a learning experience for myself and that I could feel like I at least wrote the majority of the script. I do appreciate all of your help with this and helping me to understand some of the pieces from your script as well.
This is what I ended up with as a final result
property monthAbbreviations : {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}
set SourceFolder to "Macintosh HD:Users:UserName:Downloads:PicturesToBeMoved:"
set DestFolder to "Macintosh HD:Shares:Pictures:DIGITALPICS:"
tell application "Finder"
set lst to name of every item in folder SourceFolder
repeat with i from 1 to count lst
tell lst's item i to set {theMonth, theDay, theYear} to {text 1 thru 2, text 3 thru 4, text 5 thru 8}
if theYear ≥ "2014" then --starting new naming structure in 2014
set the_FullFile to POSIX path of SourceFolder & lst's item i
set FolderName to theMonth & item (theMonth as integer) of monthAbbreviations & theYear
set the_FullDest to POSIX path of DestFolder & theYear & "/" & FolderName
do shell script "/usr/bin/ditto " & the_FullFile & space & the_FullDest
do shell script "/bin/rm " & the_FullFile
end if
end repeat
end tell
I think it is a pretty good compromise between the finer details of your script and the basics I am trying to learn in my script. Let me know if you think I have missed anything. Thanks.
POSIX paths in shell calls should always be put in quotes to avoid errors in case the path contains space characters.
e.g.
set the_FullDest to quoted form of (POSIX path of DestFolder & theYear & "/" & FolderName)
thanks StefanK. I will make changes for that.
thanks for all the help.