Creating a new folder inside the current one


I tested this one

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)
				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

Yvan KOENIG (from FRANCE mardi 6 février 2007 21:01:02)

Hi Yvan,

I noticed in this last script (not yours), that when it was run, the subfolders would do this:

Clients–>Client name–>2006–>2006–>thenthefiles.ext

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}
           move F to folder the_year
       end try
   end repeat
end repeat


:lol:, of course you get a mess, if you run the script more than once

Good thing there is a backup… :stuck_out_tongue: 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.

Excellent. This works well, thanks :smiley:



My script takes care of existing folder whose name is a year number.

Yvan KOENIG (from FRANCE mercredi 7 février 2007 07:35:18)