Sunday, November 19, 2017

#1 2012-05-10 03:10:26 pm

DPaquin
Member
Registered: 2012-01-23
Posts: 69

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


Filed under: dd-mm-yy-hh-mm-ss

Offline

 

#2 2012-05-10 05:00:21 pm

Adam Bell
Administrator
From:: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4660

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

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

Applescript:


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


iMac running OS X 10.13.1

Offline

 

#3 2012-05-11 12:12:07 am

regulus6633
Member
From:: Taulov, Denmark
Registered: 2006-11-02
Posts: 1695
Website

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

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...

Applescript:

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

Last edited by regulus6633 (2012-05-11 12:16:51 am)

Offline

 

#4 2012-05-11 02:30:42 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3201

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

DPaquin wrote:

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


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

Applescript:


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 :

Applescript:


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

Applescript:


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 :

Applescript:


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

Applescript:


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

Last edited by Yvan Koenig (2012-05-11 03:00:39 am)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)