in reply to Re^4: File creation and last modifiication time
in thread File creation and last modifiication time

JavaFan is right, these google links aren't just "plug it in" deals.

First, you need to decide if "creation time" is really what you want. That is the time that the file was created to begin with (and of course never changes) and is NOT the time the file was last modified.

When you create the file, the creation time and last modified times are the same, then they diverge every time file is updated. Almost always what is needed is the last modification time. On Windows NTFS, it is possible to get the creation time, but I think you'll have to go to the Win api to get it via a Perl function call. There is no standard Perl file test operator for creation and I don't even think it is available on Unix.

In the WinXP command shell type: "help DIR" and you will see that you can get that creation info, last accessed and last written. DIR drive:pathfilename [/A[:attributes]] /B /C /D /L /N [/O[:sortorder]] /P /Q /S [/T[:timefield]] /W /X /4

So what you asked for, "creation" time is saved by the NT filesystem, but I don't think that is what you want.

Proceeding on the assumption that you want to use a combination of -f (plain file, not a directory) and -M modification date, then you need a strategy to arrive at what you want.

. -M is the age of file (at startup) in Days. You might get a number for a recent file like this: 1.86696759259259. That number is relative to the time that this Perl program is running. For your requirement, the absolute modification date doesn't appear to matter. So, run a sort on the -M file test (like the size example), pick first and last, then subtract those numbers. This difference will be expressed in days, so do some appropriate division by 24, 60 stuff to get this into say days:hours:minutes:seconds if that is what you need for your report. I mean 1.86696759259259 is a bit incomprehensible.

Remember that a directory is a file, so you will need the -f file test also if you just want "plain files", which appears likely.

I hope I've given you a starting place for you to give this an attempt by yourself. So go at it. Its likely that some sort of problem will develop, but then you post your code, a simple example that demonstrates the problem and we go from there!

  • Comment on Re^5: File creation and last modifiication time