Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: To count number of files created yesterday in a directory

by Cristoforo (Curate)
on Feb 04, 2017 at 00:31 UTC ( [id://1181041]=note: print w/replies, xml ) Need Help??


in reply to To count number of files created yesterday in a directory

Using Time::Piece and Time::Seconds, (in the core since perl version 5.9.5), you can get the count of files created yesterday with the code below.
#!/usr/bin/perl use strict; use warnings; use Time::Piece; use Time::Seconds; my $t = localtime() - ONE_DAY; # yesterday my $count = grep {$t->ymd eq localtime( (stat)[9] )->ymd} glob "*.*";
(I was not able to use the code below, even though the documentation for Time::Piece says '==' is possible.)

my $count = grep {$t == localtime( (stat)[9] )} glob "*.*";

Update: Of course it wouldn't work as it's comparing 'ymdhms' rather than 'ymd'.

Replies are listed 'Best First'.
Re^2: To count number of files created yesterday in a directory
by hippo (Bishop) on Feb 04, 2017 at 11:18 UTC
    glob "*.*";

    Note that the above glob will only match files/dirs containing a dot. If memory serves, this is a Microsoftism because in their world a simple glob "*" doesn't match all entries like it would on other platforms.

    Luckily there are things like File::Glob to help with making such actions platform-independent.

      Hi hippo,

      a simple glob "*" doesn't match all entries like it would on other platforms

      At least on Linux, glob "*" skips entries beginning with a dot, to get those you need glob ".* *".

      Regards,
      -- Hauke D

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1181041]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-25 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found