Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

name of the last file

by basheer (Novice)
on Nov 09, 2011 at 06:10 UTC ( [id://936961]=perlquestion: print w/replies, xml ) Need Help??

basheer has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have to read the directory and fetch the txt file and match the name (partial_pressps_report), if the file name contains (partial_pressps_report$i) $i(1 or 2 or 3) then ($i) should be incremented and printed

use strict; use warnings; my $topdir = 'D:/PGN/ELSEVIER/FNS/1(1)/press'; opendir(HU, "$topdir"); my @files = grep(/\.txt$|.TXT$/,readdir(HU)); closedir(HU); my $ucount = 0; foreach(@files) { my $frame = $files[$ucount]; if($frame =~m#^partial_pressps_report#gs) { my $frameu = my $frame; } else { print "$frame"; } $ucount++; }

Thanks,

W. Ahmed

Replies are listed 'Best First'.
Re: name of the last file
by ansh batra (Friar) on Nov 09, 2011 at 06:47 UTC
    use strict; use warnings; my $topdir = '/home/ansh/perlmonks'; opendir(HU, "$topdir"); my @files = grep(/\.txt$|.TXT$/,readdir(HU)); closedir(HU); #print "@files"; #my $ucount = 0; foreach my $file(@files) { #my $frame = $files[$ucount]; if($file =~ /^p(1|2|3)/) { print "$file\n"; # my $frameu = my $frame; } else { #print "$frame"; } # $ucount++; }


    output
    p1.txt p3.txt p2.txt


    does this solve your problem???

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-03-29 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found