Folder action to rename files
Folder action to rename files
- Subject: Folder action to rename files
- From: pete boardman <email@hidden>
- Date: Wed, 24 Aug 2005 13:20:23 +0100
I'm having trouble with this folder action, which is supposed to add
a date stamp to a file's name when added to a folder. It seems to
repeat the renaming action on the same file each time when I add a
bunch of files. Can anyone point out my error?
--
on adding folder items to this_folder after receiving these_items
try
set isoD to datestr(current date)
repeat with i in these_items -- a list of files?
set fn to name of (info for i)
set fne to name extension of (info for i)
set fneoffset to name extension of (info for i)
-- get name without extension...
set fname1 to (characters 1 thru ((offset of fneoffset
in fn) - 2) of fn) as text
set newName to fname1 & "-" & isoD & "." & fne
tell application "Finder"
set name of i to newName
end tell
end repeat
on error e
tell application "Finder" to display dialog e as text
end try
end adding folder items to
on datestr(theDate)
-- returns eg 2004-11-28
set m to month of theDate as integer
set theShortDate to (theDate's year as text) & "-" & text -2
thru -1 of ("0" & m) & "-" & text -2 thru -1 of ("0" & theDate's day)
return theShortDate
end datestr
--
Thanks for any pointers!
Pete
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden