Deleting files with Applescript

Joined
Mar 28, 2006
Messages
198
Reaction score
5
I've got a script that is supposed to delete all files from specific folders that are older than 60 days... I tested it with only 2 folders set to delete and it worked perfectly... then I added all the other folders in the same manner... basically, I want it to check every day for files that are older than 60 days... When I ran it the first time I didn't have the "on idle" or "try" set... added those once it appeared to be functioning... Now I get an error that says "Finder got an error: can't make some data into the expected type."... it compiles as is but something must be wrong... little help?

on idle
try

tell application "Finder"
delete (every item of folder "Bailey-Originals" of folder "Bailey" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Bailey-Bad" of folder "Bailey" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Bailey-Good Reports" of folder "Bailey" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Bailey-Warning Reports" of folder "Bailey" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))

delete (every item of folder "Lisa-Originals" of folder "Lisa" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Lisa-Bad" of folder "Lisa" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Lisa-Good Reports" of folder "Lisa" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Lisa-Warning Reports" of folder "Lisa" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))

delete (every item of folder "Andrea-Originals" of folder "Andrea" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Andrea-Bad" of folder "Andrea" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Andrea-Good Reports" of folder "Andrea" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Andrea-Warning Reports" of folder "Andrea" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))

delete (every item of folder "Birgit-Originals" of folder "Birgit" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Birgit-Bad" of folder "Birgit" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Birgit-Good Reports" of folder "Birgit" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Birgit-Warning Reports" of folder "Birgit" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))

delete (every item of folder "Jennifer-Originals" of folder "Jennifer" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Jennifer-Bad" of folder "Jennifer" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Jennifer-Good Reports" of folder "Jennifer" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Jennifer-Warning Reports" of folder "Jennifer" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))

delete (every item of folder "Megan-Originals" of folder "Megan" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Megan-Bad" of folder "Megan" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Megan-Good Reports" of folder "Megan" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
delete (every item of folder "Megan-Warning Reports" of folder "Megan" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
end tell
end try
end idle


thanks...
Zeyhra
 

Ric

Joined
May 14, 2004
Messages
4,245
Reaction score
5
Hi there,

Zeyhra try this... (no pun intended !)

Code:
on idle
	tell application "Finder"
		try
			delete (every item of folder "Bailey-Originals" of folder "Bailey" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Bailey-Bad" of folder "Bailey" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Bailey-Good Reports" of folder "Bailey" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Bailey-Warning Reports" of folder "Bailey" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Lisa-Originals" of folder "Lisa" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Lisa-Bad" of folder "Lisa" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Lisa-Good Reports" of folder "Lisa" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Lisa-Warning Reports" of folder "Lisa" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Andrea-Originals" of folder "Andrea" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Andrea-Bad" of folder "Andrea" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Andrea-Good Reports" of folder "Andrea" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Andrea-Warning Reports" of folder "Andrea" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Birgit-Originals" of folder "Birgit" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Birgit-Bad" of folder "Birgit" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Birgit-Good Reports" of folder "Birgit" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Birgit-Warning Reports" of folder "Birgit" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Jennifer-Originals" of folder "Jennifer" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Jennifer-Bad" of folder "Jennifer" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Jennifer-Good Reports" of folder "Jennifer" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Jennifer-Warning Reports" of folder "Jennifer" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Megan-Originals" of folder "Megan" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Megan-Bad" of folder "Megan" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Megan-Good Reports" of folder "Megan" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
		try
			delete (every item of folder "Megan-Warning Reports" of folder "Megan" of disk "PitStop Server" whose modification date is less than ((get current date) - 60 * days))
		end try
	end tell
end idle

Haven't tried it but the logic seems correct...

The way you had it, if it did the first, second , third folder etc and there was nothing to delete the 'try' block would finish the script without 'trying' anything else...

This way it 'trys' each folder on it's own merits and moves on to the next regardless of the previous folder

regards

Ric
 

Ric

Joined
May 14, 2004
Messages
4,245
Reaction score
5
No problem...

Probably not the neatest bit of code, but if it works !

regards

Ric
 
Joined
Mar 28, 2006
Messages
198
Reaction score
5
It doesn't have to be pretty as long as it works... thanks again!
Zeyhra
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top