Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding stats in subdirectories 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I want to be able to find modificiaton times in all my subdirectories. Please advise what I am doing wrong.


use strict;
my $finder = $File::Find::name; #not sure what to do here.
my $newfile = "/perl/bin/";

opendir(DIR,$newfile);
my @files = readdir(DIR);
close(DIR);

chdir ($newfile) or die "Could not change to $newfile directory\n$!\n";
for(@files) {

my $filename = $_;
next if ($_ != m/^\.+$/);
my $modtime = localtime ( (stat($filename))[9] );

print "file name : $filename\n";
print "MODIFICATION time : $modtime\n";
}
 
You need to tell it the directory name to get the correct mtime

my $modtime = localtime ( (stat($newfile.$filename))[9] );

Otherwise it seemed to work fine.
However, I found that I didn't need
my $finder = $File::Find::name; #not sure what to do here.

or
chdir ($newfile) or die "Could not change to $newfile directory\n$!\n";


HTH
tgus

____________________________
Families can be together forever...
 

I tried as suggested but it still only searches and list files in current directory. I need it to search all subdirectories of current directory and list all the subdirctories and files modification times.
 
Hi,

check this out.Set the @ENV variable in the beginning of your program.
my $newfile = "/perl/bin/";
my $PATH = $ENV{PATH};
$ENV{PATH}= "$PATH".$newfile;
Then add the other lines of code.



 
use File::Find like this
Code:
use File::Find;

my @directories = ("/perl/bin");
find(\&wanted, @directories);

sub wanted {

    unless (/^\..?$/) {
        print "filename : $_\n";
        my $modtime  = localtime ( (stat($_))[9] );
        print "MODIFICATION time : $modtime\n";
    }
}

It will decend the directory tree automatically.

jaa
 
Thanks,

Long shot question:
Anyway to get the inode time for file creation on an NT?

I tried the:
my $creationtime = localtime ( (stat($_))[10]
instead of
my $modtime = localtime ( (stat($_))[9]

but it does not give me the file creation, instead it gives mod time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top