Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Terminal command to change files/folders creation/modification date

Hello,


I'm looking for a terminal command that allows me to change files and folders creation and modification date.

I've already tried with:

touch -t YYYYMMDDhhmm.ss [File path]

--to change creation date


or


touch -mt YYYYMMDDhhmm.ss [File path]

--to change modification date

...but the command to change the creation date doesn't work (changes only the modification date) and the other command to the same as the first.

Moreover using touch command I'm not able to change folders' properties.


Any suggest?

Thanks in advance!

Posted on Aug 18, 2014 1:08 AM

Reply
18 replies

Feb 9, 2015 10:33 PM in response to Jacques Rioux

Jacques/All;


I am out trawling for code and happened upon this.


I can't seem to get this coded without a syntax error. I also substituted line 9 with your f = sys.argv[1].decode(\"utf8\".

I get:

File "<string>", line 1

import sys from Foundation import NSFileManager, NSDateFormatterdm = NSFileManager.defaultManager()

^

SyntaxError: invalid syntax


Any ideas?

Feb 10, 2015 9:25 AM in response to Jon P

Hi,


Jon P wrote:


Jacques/All;


I am out trawling for code and happened upon this.


I can't seem to get this coded without a syntax error. I also substituted line 9 with your f = sys.argv[1].decode(\"utf8\".

I get:

File "<string>", line 1

import sys from Foundation import NSFileManager, NSDateFormatterdm = NSFileManager.defaultManager()

^

SyntaxError: invalid syntax


Any ideas?


According to the error, the end of lines (linefeed) in the python script are missing.


Use another browser to copy the script.

Or use this handler (I replace the end of line by \n, the AppleScipt editor will replace them automatically when compile) :


on setCreationDate(f, d)
    do shell script "/usr/bin/env python -c 'import sys\nfrom Foundation import NSFileManager, NSDateFormatter\ndm=NSFileManager.defaultManager()\nf=sys.argv[1].decode(\"utf8\")\ndf=NSDateFormatter.new()\ndf.setDateFormat_(\"yyyyMMddHHmmss\")\ncdate=df.dateFromString_(sys.argv[2])\ncDateDict={\"NSFileCreationDate\": cdate}\nb, error=dm.setAttributes_ofItemAtPath_error_(cDateDict , f, None)\nif not b: print f' " & f & " " & quoted form of d
end setCreationDate

Terminal command to change files/folders creation/modification date

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.