Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'use filename for creation date info?' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
use filename for creation date info?
Authored by: spacericker9k on Jul 11, '06 09:07:13AM

here you go....
-save it as an application using script editor
-to use, drag and drop files onto it
-very important...the script assumes that underscores separate the date AND that the date is the second piece of info in the filename. as in: RCR_19971225_AA36.psd
-it also assumes that the date in the filename is formatted as YYYYMMDD
-for the hour and minute part, the script adds 0000, which is 12:00am

on open files_
repeat with file_ in files_
tell application "Finder"
set file_name to name of file_
set AppleScript's text item delimiters to {"_"}
set new_creation_date to second text item of file_name
set new_creation_date to new_creation_date & "0000"
set file_ to POSIX path of file_
do shell script "touch -t " & new_creation_date & " " & quoted form of file_
end tell
end repeat
end open



[ Reply to This | # ]
recommend restoring AS TIDS
Authored by: Krioni on Jul 13, '06 04:02:25PM
I always recommend restoring the AppleScript's text item delimiters to whatever they were before changing them (just in case you use this in a subscript):


on open files_
	repeat with file_ in files_
		tell application "Finder"
			set file_name to name of file_
			set od to AppleScript's text item delimiters
			set AppleScript's text item delimiters to {"_"}
			set new_creation_date to second text item of file_name
			set new_creation_date to new_creation_date & "0000"
			set file_ to POSIX path of file_
			do shell script "touch -t " & new_creation_date & " " & quoted form of file_
			set AppleScript's text item delimiters to od
		end tell
	end repeat
end open

---
http://www.danshockley.com

[ Reply to This | # ]

recommend restoring AS TIDS
Authored by: ctierney on Jan 03, '07 10:00:34AM
That's good advice to restore TIDS. Here's another method that off loads the filename parsing to sed. Not nearly as readable, but any non digit can be the delimiter:
on open files_
	repeat with file_ in files_
		tell application "Finder"
			set file_name to name of file_
			set file_ to POSIX path of file_
			do shell script "touch -t `echo " & file_name & " | sed -ne 's/.*\\([0-9]\\{8,8\\}\\).*/\\10000/p'` \"" & file_ & "\""
		end tell
	end repeat
end open


[ Reply to This | # ]
change date/time - different format
Authored by: idarryl on Feb 06, '08 07:33:11AM

Hi Guys,

(sucking up section - skip ahead for the real question)
I'm sorry to bug you - I'm sure you don't want to write personalised scripts for everyone, however I have been trying to figure something out for myself for a few hours now using your *wonderful* scripts as a head start, and I just can't work it out.


I'm trying to do the same thing but with iChat log files, the file format is a little more difficult "Persons Name on 2007-08-04 at 13.56.ichat", if possible I would like to set the time as well, as iChat logs are pretty time sensitive for me.

Unfortunately, when I moved ove to Leopard, the date and time were reset!!

Thanks for your help



[ Reply to This | # ]