[MacOS Ventura]
I need to move some files off a drive that is nearing its capacity to another drive while preserving the original Date Added
in its new location. Since I've noticed that MacOS sometimes resets the Date Added
attribute when I use Finder
to move files around, including when a file is moved to another drive, I am planning to write a bash
script that will move the files for me and then set the date attributes when the move finishes.
In preparation for writing my script, I have been examining the results of several ways of retrieving the date attributes of my files. I've tried stat
, gstat
, and GetFileInto
so far but none of them give me what I want, reliably (i.e. the result matches what Finder
shows in its window). Since I have excluded my source drive from Spotlight's indexing service, I cannot use mdls
for this.
GetFileInfo
returns the created
and modified
dates, but neither of them match Finder
's Date Added
date.
Using stat -f %Sc -t "%Y-%m-%d %I:%M:%S%p" <pathToFile>
to display the file's st_ctime
seems to return a date/time that is very close to Finder
's Date Added
date but it frequently differs by minutes or even hours (which are not related to time-zone adjustments). See image Finder/Console screenshots below and note the time difference :
Using gstat -c%z <pathToFile>
to display the file's last status change, gstat
's equivalent of the above stat
command, produces the same problem.
Would anyone be able to suggest other ways of doing this, including the use of other languages; e.g. python or C/C++, or tools; e.g. debugfs
, that will always return the same date/time as Finder
shows?
Date Added
. And, it doesn't explain why thest_ctime
is out by hours.