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!


In reply to Re^5: File creation and last modifiication time by Marshall
in thread File creation and last modifiication time by mecrazycoder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.