Help - script to move folders based on Modification date?

I have cobbled together a few scripts from this site

  • but I seem to be having trouble. I need AS to search
    a pre-defined directory on one server for any
    folders older than say 90 days and move them
    to another server for archiving. I seem to be
    having problems getting the date modified
    info from the folder?

The following should help you get going …


tell application "Finder"
	set the_Folder to choose folder with prompt "Choose a Folder:"
	set the_Info to info for the_Folder
	set the_Date to modification date of the result
	display dialog the_Date as text
end tell

Good Luck :oops:

This could get you started:

tell application "Finder" to move ¬
	(folders of alias "path:to:dir:" whose modification date is less than ((current date) - 90 * days)) ¬
		to desktop

Thanks Gents! Just the ticket!
BUT…here is the error I get on run:

-Finder got an error: Can’t get every folder of alias “Macintosh HD/test”.-

happens no matter what directory I choose?

tell application “Finder” to move ¬
folders of alias “Macintosh HD/test” to desktop
end

In AppleScript (note the colons and slashes as dir-separators):

Alias = alias “disk:folder:file”
File path = file “disk:folder:file”
POSIX path = “/folder/file”
Finder reference =

  • folder “disk:folder:”
  • folder “folder” of startup disk of application “Finder”
  • file “disk:folder:file”
  • file “file” of folder “folder” of startup disk of application “Finder”

Finder references are valid only when you are scripting the Finder, POSIX path is mostly used in “do shell script” statements, file path is used only some times, alias is mostly universal.

As you guessed, the Finder is looking in your code for the disk “Macintosh HD/test” (instead of the folder “test” inside of the disk “Macintosh HD”), which does not exist.

Thanks jj - everything is working like a charm - I’ll post my final script next - you guys rock!


mount volume "afp://xxx.xxx.x.xx/server"
mount volume "afp://xxx.xxx.x.xx/server1"
mount volume "afp://user:pass@xxx.xxx.x.xx/brisque4impo.3.0/Imposed_Jobs"

display dialog "Archive files Older than how many Days?" default answer "90"
set n to text returned of the result

repeat
	set theFolder to alias choose folder
	
	with timeout of 1200 seconds
		tell application "Finder" to move ¬
			(every folder in theFolder whose modification date is less than ((current date) - (n * days))) ¬
				to "server1:Archives" as alias
	end timeout
	tell application "Finder" to delete (every folder in theFolder whose modification date is less than ((current date) - (n * days)))
	
end repeat


this worked just dandy!

javascript:emoticon(‘:D’)

So now that that works like a charm my problem is this:

On our server we store jobs in their own folder with one more level
of folders within which contain various files (brisque, postscript, etc…)
Is it possible to check the modification date of the top folder and the date of sub folders?

Otherwise it may pull active jobs off the server!??

any thoughts?

If you use “entire contents of theFolder” instead of “theFolder”, it will reference to any nesteeds folders inside “theFolder”, but you still should loop through the result and see what items are owned by what folder.

You are a saint!

So here is my final script - it seems to be working fine!
If anyone spots a problem or redundancy (I’m sure there are)
I would appreciate knowing.

The script mounts designated network servers
prompts the user to enter over how many days old the folders to archive should be.
it then checks all the folders in the specified directory AND their subfolders
for a modification date older than specified.
it then moves these to a specified folder for archiving via retrospect
and deletes them off the server. The folders copy and delete one at a time
I know this is lengthy but in the event of an error on the system or by the operator
it is easier to fix.

The script uses Jon’s Commands: http://www.seanet.com/~jonpugh/

mount volume "afp://user:pass@xxx.xxx.x.xx/server"
mount volume "afp://user:pass@xxx.xxx.x.xx/server1"
mount volume "afp://user:pass@xxx.xxx.x.xx/brisque4impo.3.0/Imposed_Jobs"



display dialog "Archive files Older than how many Days?" default answer "90"

set n to text returned of the result

set destFolder to "path:folder:"

set theDate to ((current date) - (n * days))

repeat
	
	set theFolder to alias choose folder
	set x to 2
	
	with timeout of 120000 seconds
		
		tell application "Finder" to set the folder_list to every folder of theFolder
		repeat with aFolder in folder_list
			set x to 2
			
			if the modification date of aFolder is greater than theDate then set x to 1
			
			tell application "Finder" to set the sub_list to every item of aFolder
			repeat with subFolder in sub_list
				if the modification date of subFolder is greater than theDate then set x to 1
				
			end repeat
			
			
			if x is 2 then move aFolder to destFolder with unlocking and replacing without safetynet
			if x is 2 then delete aFolder with unlocking without safetynet
			
		end repeat
	end timeout
end repeat