Mac OS X stores file creation time, and I know how to read it with stat()
from <sys/stat.h>
.
I could not find a way, how to set the creation time in C. It must be possible somehow, as the utility SetFile
can do it (SetFile
is part of the command line tools package from Apple):
SetFile -d '12/31/1999 23:59:59' file.txt
How can I do it in C?
To change the Modified timestamp to the current date and time, type "touch -m" in Terminal, followed by one space. Then drag the file from Finder into Terminal and press "Enter." Enter a space after the time and drag the file into the Terminal window. Press "Enter" to make the change.
But yes, just go to the Finder, press Command + F to bring up a Finder window, then change the filters to search "This Mac", and "Last modified date" is "after" <your date> to see all your modified documents.
Click the blue, smiling face icon in your Mac's Dock to open Finder. Click the file you want to change. Clicking the file one time will select that file without opening it. To edit the properties of more than one file at a time, hold down the Control key as you click each file.
You can use utimes.
If times is non-NULL, it is assumed to point to an array of two timeval structures. The access time is set to the value of the first element, and the modification time is set to the value of the second element.
And:
For file systems that support file birth (creation) times (such as UFS2), the birth time will be set to the value of the second element if the second element is older than the currently set birth time. To set both a birth time and a modification time, two calls are required; the first to set the birth time and the second to set the (presumably newer) modification time
As an example:
struct timeval times[2];
memset(times, 0, sizeof(times));
times[0].seconds = 946684799; /* 31 Dec 1999 23:59:59 */
times[1].seconds = 946684799;
utimes("/path/to/file", ×);
If the modification time passed is older than the current creation time of the file, the creation time will be set. You can then call utimes
again if you want to set a different modification time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With