Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Read Directory and getlines in .csv

by Ovid (Cardinal)
on Apr 27, 2016 at 17:12 UTC ( [id://1161660]=note: print w/replies, xml ) Need Help??


in reply to Read Directory and getlines in .csv

I know not everyone is a fan of File::Find::Rule, but I'm so used to it that it's just a quick hack for me. The following returns a list of all files with a .csv extension, in a given directory, modified within the last 24 hours. The rest, of course, should be straightforward after this.
use File::Find::Rule; my $dir = 'lib'; # or wherever they're located my $last_24_hours = time - 86_400; my @files = File::Find::Rule->file->name('*.csv')->mtime(">$la +st_24_hours")->in($dir);

Replies are listed 'Best First'.
Re^2: Read Directory and getlines in .csv
by Cristoforo (Curate) on Apr 27, 2016 at 20:14 UTC
    Note that this will recurse into subdirectories of $dir if they exist. His code does not.

    I'm not sure how you could achieve that.

    Update: I believe this addition to the rule will achieve that.

    my @files = File::Find::Rule->file->name('*.csv')->maxdepth(1)->mtime(">$last_24_hours")->in($dir);

    Update: poj's use of glob would probably be the better solution

Re^2: Read Directory and getlines in .csv
by Dipepper (Novice) on Apr 27, 2016 at 17:24 UTC

    Great idea to use File::Find::Rule Thank you!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-04-23 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found