Setting created timestamp of files using BasicFileAttributeView

Michael Hall mik3hall at gmail.com
Sat Mar 5 14:23:34 UTC 2016


> On Mar 5, 2016, at 7:15 AM, Robert Krüger <krueger at lesspain.de> wrote:
> 
> Hi,
> 
> could anyone tell me if setting the created time of a file via
> BasicFileAttributeView is not supported on OSX? I tried using the following
> code snippet:
> 
> BasicFileAttributeView attributes =
> Files.getFileAttributeView(Paths.get(file.getAbsolutePath()),
> BasicFileAttributeView.class);
> FileTime time = FileTime.fromMillis(someNewTimeInMillis);
> attributes.setTimes(time, time, time);
> 
> Finder displays last modified and last opened (i.e. last accessed, I
> assume) as the value specified by someNewTimeInMillis but created remains
> at the old value.
> 
> Is this simply not supported on OSX and I have to use a native call to do
> this?

This…,
https://stackoverflow.com/questions/9198184/setting-file-creation-timestamp-in-java <https://stackoverflow.com/questions/9198184/setting-file-creation-timestamp-in-java>
seems to suggest that File.setLastModified will accomplish what you wan on OS Xt.

You would probably want to check on the nio dev list to see if this is considered a bug or expected behavior on OS X.

If default nio file attributes don’t work and you really want that approach for what you are doing, then before getting into native yourself you could take a look at my trz project…
https://github.com/mik3hall/trz <https://github.com/mik3hall/trz>

It has a nio OS X specific filesystem. A lot of what actually works is exposing different native file api’s as attributes. One of them may already support this, I don’t remember. If you find a native api that does support this and my implementation of it’s attributes does not, let me know, I’ll add it.

Michael Hall






More information about the macosx-port-dev mailing list