For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > April 2004 > number of files in a dir









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author number of files in a dir
Karl

2004-04-23, 5:37 pm

Hi all.

Is there a module or function which will return the number of files in a dir
or at least have similar results as

ls -1 | wc -l

Tks
--
Karl

Wiggins D Anconia

2004-04-23, 6:32 pm



> Hi all.
>
> Is there a module or function which will return the number of files in

a dir
> or at least have similar results as
>
> ls -1 | wc -l
>


perldoc -f opendir
perldoc -f readdir

http://danconia.org
John W. Krahn

2004-04-23, 9:34 pm

Karl wrote:
>
> Hi all.


Hello,

> Is there a module or function which will return the number of files in a dir
> or at least have similar results as
>
> ls -1 | wc -l


For the same results as above:

my $number_of_files = () = <*>;


However that also includes directory names and does not include "hidden"
files.

# only file names
my $number_of_files = grep -f, <*>;

# include hidden files
my $number_of_files = grep -f, <* .*>;



John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com