Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Only files starting with xxxx

by amitbhosale (Acolyte)
on Feb 14, 2008 at 09:04 UTC ( #667895=note: print w/replies, xml ) Need Help??


in reply to Only files starting with xxxx

Hi,
Below mentioned script list's the files starting with "xxx"
#!/usr/bin/perl -w use strict; sub dodir { opendir(DIR,$_[0]) or die "Couldn't open $_[0] directory $!"; my $dir=$_[0]; if ( $dir !~ /\/$/ ) { $dir .= "/"; } my @List=readdir(DIR); closedir(DIR); splice(@List,0,2); foreach my $file (@List) { $file = $dir.$file; if( -d $file) { dodir($file); } elsif ($file =~ /xxx*/ ) { print "\n File $file is present in $di +r"; #print "\n File type: ",stat($file)->mode; } } } my $dir_name="/home"; if ( -d $dir_name) { dodir($dir_name); }
========o/p======
File /home/myprog/xxxabc is present in /home/myprog/ File /home/myprog/xxxpqr is present in /home/myprog/

Originally posted as a Categorized Answer.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2023-02-02 07:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (15 votes). Check out past polls.

    Notices?