FAQ
Hi, i wonder how i can get only the files that are modified
less than a hour for exemple in a directory.
How can i do this in Perl?
Thanks.

Search Discussions

  • John W. Krahn at Sep 27, 2002 at 11:00 am

    JGONCALV@bouyguestelecom.fr wrote:

    Hi, i wonder how i can get only the files that are modified
    less than a hour for exemple in a directory.
    How can i do this in Perl?

    Use stat or lstat to get the mtime and compare it to the current time.
    The times used are in seconds so one hour would be 3600 seconds.

    Using a file glob:

    my @files = grep time - (lstat)[9] < 3600, <directory/*.txt>;


    Or using opendir and readdir:

    my $dir = 'directory';
    opendir D, $dir or die "Cannot open $dir: $!";
    my @files = grep time - (lstat "$dir/$_")[9] < 3600, readdir D;
    closedir D;




    John
    --
    use Perl;
    program
    fulfillment

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedSep 27, '02 at 8:24a
activeSep 27, '02 at 11:00a
posts2
users2
websiteperl.org

2 users in discussion

John W. Krahn: 1 post Jgoncalv: 1 post

People

Translate

site design / logo © 2022 Grokbase