Re: question about # of files in a directory
- From: japhy@xxxxxxxxxxxx (Jeff 'japhy' Pinyan)
- Date: Fri, 30 Sep 2005 10:09:57 -0400 (EDT)
On Sep 28, ZHAO, BING said:
Is there a way to call or maybe get the # of files in a
directory?
The simplest way is to use opendir() and readdir().
opendir my($dh), $path or die "can't opendir $path: $!";
my @files = readdir $dh;
closedir $dh;
Now you have the files from the directory $path in the array @files. The
number of elements is the number of files.
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://www.perlmonks.org/ % have long ago been overpaid?
http://princeton.pm.org/ % -- Meister Eckhart
.
Relevant Pages
- Re: how do I know if its an array?
... check boxes. ... How will I know if I have an array or not? ... RPI Acacia Brother #734 % the cheated, we who for every service http://www.perlmonks.org/ % have long ago been overpaid? ... (perl.beginners) - Re: References Question
... the second is getting an element in the array referred to by $this. ... print $ref[2]; ... RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? ... (perl.beginners) - RE: Cant use subscript in angle brackets
... Second of all, you should not be using `ls ...` for this, because Perl offers you opendir, readdir(), and closedir. ... Now you have all the file *names* in an array. ... of the array both as paths to files AND as the filehandles themselves. ... Now for every element in @dbfiles, the matching element in @fh is a filehandle for it. ... (perl.beginners) - Re: Using a variable in a =~ match??
... and search that file for specific phrases. ... 13 while ($file = readdir DH){ ... my @array = readdir DH; ... character in a regular expression matches every character so you have to escape it to match a literal. ... (perl.beginners) - Re: fileorder of readdir()
... Subject: fileorder of readdir() ... > An alternative is to read the files into an array and sort them, ... Try to put all folder content with readdirto an array, ... function cmp ... (comp.lang.php) |
|