CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
number of files in folder....

 



ultimategamer2k
User

Mar 24, 2001, 7:58 PM

Post #1 of 4 (556 views)
number of files in folder.... Can't Post

how can i find out the number of files in a directory?
not the names, but the number
thanks!

-------------------------------------------------------------
visit my web site at <a href=http://ultimategamer.cjb.net>here</a>


Jasmine
Administrator / Moderator

Mar 25, 2001, 10:10 AM

Post #2 of 4 (549 views)
Re: number of files in folder.... [In reply to] Can't Post

For files ending in .cgi:


Code
my $filenum = grep { /\.cgi$/ } glob 'g:\home\djasmine\www\*';

For files begining with blah:


Code
my $filenum = grep { /^blah/ } glob 'g:\home\djasmine\www\*';

To get the count of just text files:


Code
my $filenum = grep {-T} glob 'g:\home\djasmine\www\*';

etc., etc., etc.

Hope this helps!



Jean
User


Mar 25, 2001, 10:11 AM

Post #3 of 4 (549 views)
Re: number of files in folder.... [In reply to] Can't Post

The following example will count the files for you.
In case you don't care whether what you found is file, dir or link, just ++ the variable unconditionally.


Code
my $dircnt = 0; 
opendir (DIR, "$dir") or die "Unable to open dir $dir";
while ( $file = readdir(DIR) ) {
$dircnt++ if (-f $file);
}
closedir (DIR);

Jean Spector
QA Engineer @ Extent Technologies, Ltd.
mage@lycosmail.com


ultimategamer2k
User

Mar 25, 2001, 5:24 PM

Post #4 of 4 (541 views)
Re: number of files in folder.... [In reply to] Can't Post

thank you very much!

-------------------------------------------------------------
visit my web site at <a href=http://ultimategamer.cjb.net>here</a>

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives