property digits : "0123456789"
set mainFolder to (path to desktop as Unicode text) & "Clients:"
my treatFolder(mainFolder as alias)
on treatFolder(Fo)
tell application "Finder" to set nFo to name of Fo
if (length of nFo is 4) and (character 1 of nFo is in digits) and (character 2 of nFo is in digits) and (character 3 of nFo is in digits) and (character 4 of nFo is in digits) then return
tell application "Finder" to set sel2 to every item of Fo
repeat with F in sel2
set F to F as alias
tell application "Finder"
if (class of item F) is folder then
my treatFolder(F)
else
my treatFile(F)
end if
end tell
end repeat
end treatFolder
on treatFile(Fi)
tell application "Finder"
set y to year of (get creation date of Fi)
set foFi to (container of Fi) as Unicode text
set yFolder to (foFi as Unicode text) & y & ":"
if not (exists folder yFolder) then make new folder at folder foFi with properties {name:y}
move Fi to folder yFolder
end tell
end treatFile
I haven’t run your script, but does it do the same thing?
This would happen if I ran the script more than once. Is there a way to stop this from happening?
Also, just playing around and getting my feet wet I added the ‘entire contents’ command to this particular script, but it also has the same problem when running it twice.
set mainFolder to (path to home folder as Unicode text) & "Work:Clients:"
tell application "Finder" to repeat with subfolder in (get folders of entire contents of folder mainFolder)
tell subfolder to repeat with F in (get files)
set the_year to (year of (get modification date of F)) as Unicode text
if not (exists folder the_year) then make new folder at it with properties {name:the_year}
try
move F to folder the_year
end try
end repeat
end repeat
Good thing there is a backup… but since I’m constantly adding to this folder(s), I would like to just drop a file into the ‘clients name’ folder and have it organized automatically.
For this you need a different kind of script.
Now each time you start the script, new folders will be created in the year-named folders, and on, and on…
The script you need should check the folder structure and leave all year-named folders alone.