Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Antwort: Search for a file pattern in a directory tree recursively / Stoting
Hey Rajesh,

being a beginner in perl fooling around similar problems like you, I ju=
st
have the idea that you might solve the problem by using a hash to store=
the
information about the file's you have already found .

I've used
($FN,$PATH,$EXT) =3D fileparse ($File::Find::name,'\..*') ;
to separate the filename, path and extension of file found by file::fin=
d as
you may see.

What I didn't solve is to store these information in a hash to sort out=

which file's are already found as decribed in chapter 5 of the
perl-cookbook. In chapter 9 of the cookbook they describe how to find t=
he
youngest file of all in a given directory-structure like

use file::find;
@argv =3D ('.' unles @ARGV;
my ( $AGE , $name );
sub youngest {
return if defined $age && $age > ( stat($_)) [9];
$age =3D ( stat(-)) [9];
$name =3D $file::find:.name;
}
find (\&youngest, @ARGV);
print "$name ". scalar(laocaltime($age)) . "\n";

If you join these code-fragments and store filename, path, ext and age =
into
a hash or other structure you should
be able to solve your problem.

If you succeed could you please tell me how ?

Mit freundlichen Gruessen / Best regards

Manfred Beilfuss

Deutsche Verm=F6gensberatung AG
IT_Systemmanagement , DBA
M=FCnchenerstr. 1
60329 Frankfurt
Tel.: +49 (69) 2384 - 639
Fax: +49 (69) 2384 - 329
Mailto:Manfred.Beilfuss@dvag.com


=
=20
"Rajesh Dorairajan"                                =
=20
<rajesh.dorairajan@tumbl        An:     "Perl-Begin=
ners (E-mail)" <beginners@perl.org>                   =20
eweed.com>                      Kopie:             =
=20
Thema:  Search for =
a file pattern in a directory tree recursively        =20
24.03.2004 04:09                                   =
=20
=
=20
=
=20




Hello All,

I went through all the documentation and previous mail posts about
File::Find and finally decided I needed some help.

I've a directory structure I need to parse. The directory contains
subdirectories with filenames such as

full094382.db
full483292.db

Now, I need to parse through each subdirectory and pick up the name of =
the
file that was MODIFIED MOST RECENTLY. I do have a sort of a code to sta=
rt
with.

use strict;
use warnings;

$\ =3D "\n";

use File::Find;

my $localdir =3D 'C:/docs';
my @files;

find(
sub { push ( @fullcrls, $File::Find::name ) if /^(full)\w*(\.db)$/ },=

$localdir );

foreach ( @fullcrls ) {
print;
}

However, I am not able to figure how to filter out the repeat entries i=
n a
sub-directory such as

C:/docs/dir1/full094382.db
C:/docs/dir1/full483292.db
C:/docs/dir2/full482952.db
C:/docs/dir2/full930284.db
.
.
.

In the above example, I need only need filename from dir1 and dir2 that=
was
last modified. Is there a way to do this filtration in the find( sub {}
=
)
above?

Any help will be deeply appreciated.

Thanks,

Rajesh Dorairajan
rajesh.dorairajan@tumbleweed.com


=




Report this thread to moderator Post Follow-up to this message
Old Post
Manfred Beilfuss
03-27-04 04:14 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:56 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.