Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^5: Reading every file in a directory

by Kenosis (Priest)
on Sep 29, 2012 at 04:44 UTC ( #996333=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Reading every file in a directory
in thread Reading every file in a directory

Try the following on a scratch directory that contains some scratch .yml files:

use strict; use warnings; my $directory = './yml'; my $fiveDays = 5 * 86400; my $currentTime = time; my ( $fileLine, $timeStamp ); for my $YMLfile (<"$directory/*.yml">) { open my $fh, '<', $YMLfile or die $!; while ( $fileLine = <$fh> ) { last if ($timeStamp) = $fileLine =~ /login: (\d+)/; } close $fh; # Divide 13 digit TS by 1000 to convert to 10 digit TS if ( ( $currentTime - $timeStamp / 1000 ) > $fiveDays ) { print "Login TS in $YMLfile is greater than five days old.\n"; } }

Verify that the files shown by the routine have a login timestamp (TS) greater than five days. If the script is working as needed/expected, try the following on your scratch dir and files (place it on the next line after the print statement, so files are conditionally unlinked):

unlink $YMLfile or warn "Could not unlink $YMLfile: $!";

Disclaimer: Be very careful with this file-deleting script, as you're assuming all responsibility for the use of it.


Comment on Re^5: Reading every file in a directory
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2015-07-03 23:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls