T
Thieum22
Hi,
I try to go through a directory and it's subdirectories to reah the
properties of each files. But I have a problem to set active the
directory where the files are, in order to display their properties.
If anyone know how to improve my method, or know a better one, he's
welcome
Thanks,
Matthieu
here is the code :
#! /usr/bin/perl
use File::Find;
$dir_tree = '/tmp'; #test directory
# A good way to go through the subdirectories
finddepth(\&ren_dir, $dir_tree);
sub ren_dir {
next unless (-d);
print "where are we : ";
print($_ );
print "\n";
# We set the homedir
opendir(HOMEDIR, $_) || die("unable to open directory");
# chdir ($_); # make the program active only in the first
directory parsed -> why not the other ones ?
print "* we are in a directory";
print "\n";
while($filename = readdir(HOMEDIR))
{
if ($filename ne "." && $filename ne "..")
{
#we are testingif it is a file
if (-f $filename) {
print "* we've find a file";
print "\n";
print($filename);
print "\n";
# file properties
$mtime = 0;
$size = 0;
($dev, $ino, $mode, $nlink, $uid,
$gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat
$filename;
print " for example : last time
modified : ";
print($mtime);
print "\n";
}
}
}
closedir(HOMEDIR);
}
I try to go through a directory and it's subdirectories to reah the
properties of each files. But I have a problem to set active the
directory where the files are, in order to display their properties.
If anyone know how to improve my method, or know a better one, he's
welcome
Thanks,
Matthieu
here is the code :
#! /usr/bin/perl
use File::Find;
$dir_tree = '/tmp'; #test directory
# A good way to go through the subdirectories
finddepth(\&ren_dir, $dir_tree);
sub ren_dir {
next unless (-d);
print "where are we : ";
print($_ );
print "\n";
# We set the homedir
opendir(HOMEDIR, $_) || die("unable to open directory");
# chdir ($_); # make the program active only in the first
directory parsed -> why not the other ones ?
print "* we are in a directory";
print "\n";
while($filename = readdir(HOMEDIR))
{
if ($filename ne "." && $filename ne "..")
{
#we are testingif it is a file
if (-f $filename) {
print "* we've find a file";
print "\n";
print($filename);
print "\n";
# file properties
$mtime = 0;
$size = 0;
($dev, $ino, $mode, $nlink, $uid,
$gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat
$filename;
print " for example : last time
modified : ";
print($mtime);
print "\n";
}
}
}
closedir(HOMEDIR);
}