Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting date/time of creation of a file

This seems like a pretty straightforward question but I haven't been able to find a definitive answer anywhere online. How can I get the date/time a file was created through Java's file manager? Aside from just the name of a file, what else can I get about the file's "properties"?

like image 298
Brian Avatar asked Jul 30 '11 18:07

Brian


People also ask

How do I find the creation time of a file?

The command is sudo debugfs -R 'stat /path/to/file' /dev/sdaX (replace sdaX with the device name of the filesystem on which the file resides). The creation time is the value of crtime . You can add | grep . [^ca]time to list just mtime (the modification time) and crtime (the creation time).

What is the created date for a file?

What the Create Date of a file is, is actually rather self-explanatory. It is basically just the date of creation of the file in question. The is often displayed in the date format given by the computer, device or machine that created the file.

How do I get the timestamp of a file in Python?

Use getctime() function to get a creation time path. getmtime('file_path') function returns the creation time of a file. On the other hand, on Unix, it will not work. Instead, it will return the timestamp of the last time when the file's attributes or content were changed (most recent metadata change on Unix).


1 Answers

I'm not sure how you'd get it using Java 6 and below. With Java 7's new file system APIs, it'd look like this:

Path path = ... // the path to the file
BasicFileAttributes attributes = 
    Files.readAttributes(path, BasicFileAttributes.class);
FileTime creationTime = attributes.creationTime();

As CoolBeans said, not all file systems store the creation time. The BasicFileAttributes Javadoc states:

If the file system implementation does not support a time stamp to indicate the time when the file was created then this method returns an implementation specific default value, typically the last-modified-time or a FileTime representing the epoch (1970-01-01T00:00:00Z).

like image 82
ColinD Avatar answered Oct 07 '22 14:10

ColinD