Newbee21369 has asked for the wisdom of the Perl Monks concerning the following question:

I'm interested in getting a the timestamp of when the a file was written to a particular directory. Would the stat function be appropriate to use for what I'm trying to do?

Replies are listed 'Best First'.
Re: Timestamp that a file was created
by Velaki (Chaplain) on Nov 26, 2004 at 23:21 UTC

    The -M filetest will give you the elapsed time in days since the last time the file was modified.

    You could also use the tenth element of the stat command, which will return the time of last modification.

    Depends on what you need.

    Hope that helped,
    -v
    "Perl. There is no substitute."
Re: Timestamp that a file was created
by BUU (Prior) on Nov 26, 2004 at 23:53 UTC
    For future reference, Perl has a LARGE amount of documentation. Instead of asking "is this function appropiate", why don't you *read* the documentation for the function and decide for your self, rather than coming all the way here to ask a question that could have been answered after 10 seconds of work.

    perldoc -f stat perldoc.com cpan.org
Re: Timestamp that a file was created
by TedPride (Priest) on Nov 28, 2004 at 17:34 UTC
    When a file was written to a directory is not the same thing as when it was last modified. I'd think you'd want the file creation time, and the Perl stat command doesn't seem to have that:
    8 atime last access time since the epoch 9 mtime last modify time since the epoch 10 ctime inode change time (NOT creation time!) since the epoch
    And neither does the Unix stat() command:
    struct stat { ,,, time_t st_atime; /* time of last access */ time_t st_mtime; /* time of last modification */ time_t st_ctime; /* time of last change */ };
    So in answer to your question, you're pretty much out of luck unless (a) you have control of the writing and can add a few lines to a script to store the write times or (b) you know that files will only be written, not modified, in which case modification time will do fine.

    EDIT: Incidently, your answer was completely useless, BUU. If it's so easy to find the info, you might as well copy and paste it into your post instead of flaming the poster. --