Get file creation date in dd-mm-yy-hh-mm-ss

I need to work with two different folders. The first folder (FirstFolder) contain pictures in jpeg format and the other folder (SecondFolder) contains the same pictures in raw format.

The filename (before the extension) in FirstFolder contain the name convention I want to keep. The SecondFolder may and may not contain the same pictures contained in FirstFolder.

I need to rename the files in SecondFolder with the same name (before the extension) as the one contained in FirstFolder. A file contained in FirstFolder may or may not exist in SecondFolder. A file contained in SecondFolder must exist in FirstFolder.

The only way for me to compare files adequately for both folders is by using the timestamp each files were created.

I need to loop in both folders and compare the timestamp of the files. if there is a match I then need to rename files in SecondFolder accordingly as per FirstFolder without modifying the extension.

My question is there an applescript command which would allow me to get the file creation date in dd-mm-yy-hh-mm-ss ?

Thanks in advance!
Daniel

Assuming you want the content change date (there are several), this:


set ChangeDate to do shell script "mdls -name kMDItemFSContentChangeDate " & quoted form of POSIX path of (choose file) -- 

My question would be… why do you need it in that format? Why not just get the creation date of each file and compare that? You can compare dates in applescript. This would seem to be the applescript you need…

set folder1 to "some path"
set folder2 to "some other path"

tell application "Finder"
	set folder2Files to files of folder folder2
	repeat with aFile in folder2Files
		set thisCDate to creation date of aFile
		try
			set folder1File to (first file of folder folder1 whose creation date is thisCDate)
			-- rename aFile to the name of folder1File here
		end try
	end repeat
end tell

I dislike this format because it sorts the wrong way but here is a way to get it.


choose file
tell application "System Events" to set ChangeDate to modification date of disk item (result as text)
set newName to text -2 thru -1 of ("00" & day of ChangeDate) & "-" & text -2 thru -1 of ("00" & (month of ChangeDate as number)) & "-" & text -2 thru -1 of (year of ChangeDate as text) & "-" & (text -8 thru -7 of (ChangeDate as text)) & "-" & (text -5 thru -4 of (ChangeDate as text)) & "-" & (text -2 thru -1 of (ChangeDate as text))

I think that this one :


choose file
tell application "System Events" to set ChangeDate to modification date of disk item (result as text)
set newName to text -2 thru -1 of (year of ChangeDate as text) & "-" & text -2 thru -1 of ("00" & (month of ChangeDate as number)) & "-" & text -2 thru -1 of ("00" & day of ChangeDate) & "-" & (text -8 thru -7 of (ChangeDate as text)) & "-" & (text -5 thru -4 of (ChangeDate as text)) & "-" & (text -2 thru -1 of (ChangeDate as text))

or


choose file
tell application "System Events" to set ChangeDate to modification date of disk item (result as text)
set newName to (year of ChangeDate as text) & "-" & text -2 thru -1 of ("00" & (month of ChangeDate as number)) & "-" & text -2 thru -1 of ("00" & day of ChangeDate) & "-" & (text -8 thru -7 of (ChangeDate as text)) & "-" & (text -5 thru -4 of (ChangeDate as text)) & "-" & (text -2 thru -1 of (ChangeDate as text))

would be better.

Last not least, we may use Shane Stanley’s ASObjC Runner which gives a very clever code :


choose file
tell application "ASObjC Runner"
	set ChangeDate to modification date of (about file result)
	set newName1 to format date ChangeDate format "dd-MM-yy-hh-mm-ss"
	
	set newName2 to format date ChangeDate format "yy-MM-dd-hh-mm-ss"
	set newName3 to format date ChangeDate format "yyyy-MM-dd-hh-mm-ss"
end tell

Once the format is really selected, we may do the trick with a one-liner


tell application "ASObjC Runner" to set newName3 to format date (get modification date of (about file (choose file))) format "yyyy-MM-dd-hh-mm-ss"

Yvan KOENIG (VALLAURIS, France) vendredi 11 mai 2012 09:30:28