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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to print status of all files in directory 1

Status
Not open for further replies.

nuarj83

Programmer
Aug 30, 2006
6
US
Hi, I am new-bee in perl, i need script that prints out complete modifcations(c,a,m-times or any files added or deleted) of all files in a directory.

Any help is appreciated.
 
Hi,
You can have some things like:
Code:
foreach $filename (<*>)
{
    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
       $atime,$mtime,$ctime,$blksize,$blocks)
           = stat($filename);
     ........
}

You can refer to this page for more information:

;-)
 
For files added or deleted, you would need to maintain a data structure that you can load to compare against

Have a look at Storable.pm

HTH
--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Data::Dumper to store and load data structures:

Code:
use Data::Dumper;

# create a hashref
my $hash = {};

# load the hash keys from a file
$hash = do "./data.txt" if -f "./data.txt";

# modify the hash or whatnot...
$hash->{$filename} = 1;
$hash->{$another_filename} = 1;

# save it to a file again
open (DATA, ">./data.txt");
print DATA Dumper($hash);
close (DATA);

It should work the same with normal hashes (ie the $hash{$filename} format, without the arrows), you'd probably change the $hash=do line to %hash=do... I like working with hashrefs though for the little arrows between keys, it makes it easy to read
 
Thank you for all the valuable time and replies.
i figured out the solution and sorry for the late reply.

-arj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top