Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Checking for Files

by graff (Chancellor)
on Nov 19, 2011 at 04:00 UTC ( #938938=note: print w/ replies, xml ) Need Help??


in reply to Checking for Files

The problem that aaron_baugher pointed out is the main thing, but once you get past that, the script will take somewhat longer to run than it needs to, because you're calling the "stat" function multiple times on each file. I'd do it like this (not tested):

use strict; use warnings; use POSIX; use File::Spec; my $inputFile = "inputFileInfo.txt"; my $outputFile = strftime( "resultsFile_%Y-%m-%d_%H-%M-%S.txt", localt +ime(time())); my $pathToCheck = File::Spec->catfile( 'c:', 'temp' ); open( IN, '<', $inputFile ) or die "$inputFile: $!\n"; open( OUT, '>', $outputFile ) or die "$outputFile: $!\n"; while ( <IN> ) { chomp; my $checkFile = File::Spec->catfile( $pathToCheck, $_ ); my @stats = stat $checkFile; if ( @stats ) { printf OUT ( "%s: %d, %s\n", $checkFile, $stats[7], scalar( localtime( $stats[9] ))); } else { print OUT "$checkFile: stat failed (file not readable or not f +ound)\n"; } }


Comment on Re: Checking for Files
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (14)
As of 2014-10-20 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (88 votes), past polls