0

[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 :

enter image description here enter image description here

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?

3
  • Date added isn't a file attribute, it's a Spotlight attribute. See - apple.stackexchange.com/questions/463423/…
    – Tetsujin
    Commented Oct 5, 2023 at 16:22
  • But it's showing that field for a drive that isn't being indexed by Spotlight. Thus, it must be available some other way. This timestamp is not related to the parent folder because each fine in the folder has its own correct Date Added. And, it doesn't explain why the st_ctime is out by hours.
    – gone
    Commented Oct 5, 2023 at 17:31
  • 1
    Search on here for 'date added' you'll find many people have had many struggles trying to figure it out.
    – Tetsujin
    Commented Oct 5, 2023 at 17:54

0

You must log in to answer this question.

Browse other questions tagged .