Hi,
Because the 'touch' command only changes the modification and access times. It only changes the creation time if the target time is before the original creation time.
You must use cocoa frameworks to change the creation date of the files, or use the setFile command (need Xcode).
Or use this script:
it set the creation date of each file to the date from character 1 thru 8 in the name, the date format must be --> "03-10-14" (day-month-year).
This script keep the time of the creation date to not have "00:00:00" on all files
If the creation date is newer that the modification date, it change the modification date to the creation date
The script rename the file --> "14-10-03" (year-month-day)
-- this script rename files and set the creation date of each file to the date from character 1 thru 8 in the name (date format in the name : "03-10-14", day-month-year)
-- When the dialog will appear, just select a folder which contains files to change the name and the creation date
do shell script "/usr/bin/python -c 'from Foundation import NSFileManager, NSURL, NSString, NSDateFormatter, NSDirectoryEnumerationSkipsHiddenFiles, NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLCreationDateKey, NSURLNameKey; from AppKit import NSOpenPanel
def procFolder(fold):
p=df.contentsOfDirectoryAtURL_includingPropertiesForKeys_options_error_(fold, [NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLCreationDateKey, NSURLNameKey], NSDirectoryEnumerationSkipsHiddenFiles, None)[0]
for f in p:
r=f.getResourceValue_forKey_error_(None, NSURLIsDirectoryKey, None)
if r[0] and r[1]:
procFolder(f)
else:
myDict, error=f.resourceValuesForKeys_error_([NSURLContentModificationDateKey, NSURLCreationDateKey, NSURLNameKey], None)
if error is None:
name=myDict.get(NSURLNameKey)
if name.length > 8:
datString=name.substringToIndex_(8)
timeString=datf2.stringFromDate_(myDict.get(NSURLCreationDateKey))
cDate=datf.dateFromString_(datString + timeString)
if cDate != None: ## first 8 characters in the name is a valid date
newName=name[6:8] + name[2:6] + name[0:2] + name[8:]
dict={NSURLCreationDateKey:cDate, NSURLNameKey:newName}
if cDate > myDict.get(NSURLContentModificationDateKey): dict[NSURLContentModificationDateKey] = cDate
b, error=f.setResourceValues_error_(dict, None)
if not b: print f.path()
df=NSFileManager.defaultManager()
datf=NSDateFormatter.new(); datf.setDateFormat_(\"dd-MM-yyHH:mm:ss\") ;datf2=NSDateFormatter.new(); datf2.setDateFormat_(\"HH:mm:ss\")
op=NSOpenPanel.openPanel(); op.setCanChooseDirectories_(True); op.setCanChooseFiles_(False); op.setAllowsMultipleSelection_(False)
if op.runModal() == 1: procFolder(op.URLs()[0])' "
----------
if you have already rename these files to (year-month-day), use this script
it set the creation date of each file to the date from character 1 thru 8 in the name, the date format must be --> "14-10-03" (year-month-day).
it will not rename files.
-- this script set the creation date of each file to the date from character 1 thru 8 in the name (date format in the name : "14-10-03" (year-month-day)
-- When the dialog will appear, just select a folder which contains files to change the creation date
do shell script "/usr/bin/python -c 'from Foundation import NSFileManager, NSURL, NSString, NSDateFormatter, NSDirectoryEnumerationSkipsHiddenFiles, NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLCreationDateKey, NSURLNameKey; from AppKit import NSOpenPanel
def procFolder(fold):
p = df.contentsOfDirectoryAtURL_includingPropertiesForKeys_options_error_(fold, [NSURLIsDirectoryKey, NSURLContentModificationDateKey, NSURLCreationDateKey], NSDirectoryEnumerationSkipsHiddenFiles, None)[0]
for f in p:
r=f.getResourceValue_forKey_error_(None, NSURLIsDirectoryKey, None)
if r[0] and r[1]:
procFolder(f)
else:
myDict, error=f.resourceValuesForKeys_error_([NSURLContentModificationDateKey, NSURLCreationDateKey, NSURLNameKey], None)
if error is None:
name=myDict.get(NSURLNameKey)
if name.length > 8:
datString=name.substringToIndex_(8)
timeString=datf2.stringFromDate_(myDict.get(NSURLCreationDateKey))
cDate=datf.dateFromString_(datString + timeString)
if cDate != None: ## first 8 characters in the name is a valid date
dict={NSURLCreationDateKey:cDate}
if cDate > myDict.get(NSURLContentModificationDateKey): dict[NSURLContentModificationDateKey] = cDate
b, error=f.setResourceValues_error_(dict, None)
if not b: print f.path()
df=NSFileManager.defaultManager()
datf=NSDateFormatter.new(); datf.setDateFormat_(\"yy-MM-ddHH:mm:ss\") ;datf2=NSDateFormatter.new(); datf2.setDateFormat_(\"HH:mm:ss\")
op=NSOpenPanel.openPanel(); op.setCanChooseDirectories_(True); op.setCanChooseFiles_(False); op.setAllowsMultipleSelection_(False)
if op.runModal() == 1: procFolder(op.URLs()[0])' "