count files + dirs
From: Simon (simalt_at_totalise.co.uk)
Date: 03/31/04
- Next message: A. Sinan Unur: "Re: Array from a string."
- Previous message: Richard S Beckett: "Array from a string."
- Next in thread: Paul Lalli: "Re: count files + dirs"
- Reply: Paul Lalli: "Re: count files + dirs"
- Reply: Tad McClellan: "Re: count files + dirs"
- Reply: Jürgen Exner: "Re: count files + dirs"
- Reply: Tore Aursand: "Re: count files + dirs"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 31 Mar 2004 15:40:58 +0100
Hi,
Is there a way to count files and directories as separate entities.
If I use the following program it correctly displays the files in a
directory but also it treats subdirectories as files.
Could I not somehow code it to know that say x are files and n are
subdirectories so I know what is what?
Thanks for you help, newbie in perl.
Below is the test script.
#!/perl/bin/perl -w
use strict;
my ($count);
my $dir = 'd:/active/';
opendir DIR, $dir or die "Could not opendir $dir; Reason: $!";
my @files = grep !/^\.\.?$/ => readdir DIR;
$count=@files + 1;
closedir DIR;
foreach (@files)
{
print "File: $_ \n";
}
print "$count"-1;
result
========
D:\utils\Perl>perl read_dir.pl
File: open relay.txt
File: Server.txt
File: test
3
------------------
In the result "test" is not a file but directory and I am trying to
distinguish this from the files so it would correctly say 2 files and 1
subdirectory.
Much appreciated.
Simon
- Next message: A. Sinan Unur: "Re: Array from a string."
- Previous message: Richard S Beckett: "Array from a string."
- Next in thread: Paul Lalli: "Re: count files + dirs"
- Reply: Paul Lalli: "Re: count files + dirs"
- Reply: Tad McClellan: "Re: count files + dirs"
- Reply: Jürgen Exner: "Re: count files + dirs"
- Reply: Tore Aursand: "Re: count files + dirs"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|