note
BrowserUk
<blockquote><i>But I have 2 use <c>my @files = `attrib /s c:\\*`; my $n = scalar @files;</c> </i></blockquote>
<p>I did warn you against loading the entire list into perl. It really slows things down.
<blockquote><i> as without it says that wc is an unrecognised command </i></blockquote>
<P>There are various cures for that possible:
<ul><li>Download yourself a copy of wc.exe for Windows.
<p>It is easy to find and its a program that is just to useful to be without.
</li><li>Use <c>attrib /s c:\* | perl -nE"}{say $."</c>
<p>It is a poor substitute but works for this use.
</li><li>Use the [946578|suggestion] by [cdarke].
<p>Simple and effective.
</li></ul>
<p>But I remembered a faster method. This uses the Windows Script Host to do the donkey work via [mod://Win32::OLE] and runs 3 times faster on my machine.
<p>2:14 instead of 6:40 on my machine. It also counts the directries as it goes which may or may not be useful to you:<code>
#! perl -slw
use strict;
use Time::HiRes qw[ time ];
use Win32::OLE qw[in];
my $start = time;
my $fso = Win32::OLE->new( 'Scripting.FileSystemObject' );
my @folders = $fso->GetFolder( $ARGV[0] );
my $cFolders = 0;
my $cFiles = 0;
while( @folders ) {
local $^W;
my $folder = pop @folders;
$cFiles += $folder->Files->Count;
$cFolders += $folder->Subfolders->Count;
for my $subFolder ( in $folder->SubFolders ) {
$cFiles += $subFolder->Files->Count;
$cFolders += $subFolder->SubFolders->Count;
push @folders, $_ for in $subFolder->SubFolders ;
}
}
my $seconds = time - $start;
my $minutes = int( $seconds / 60 );
$seconds %= 60;
printf "Folders:$cFolders Files:$cFiles [%u:%.2f]\n",
$minutes, $seconds;
__END__
[12:05:12.81] c:\test>countFiles c:\
Folders:68860 Files:1234105 [2:14.00]
</code>
<div class="pmsig"><div class="pmsig-171588">
<hr />
<font size=1 >
<div>With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'</div>
<div>Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.</div>
<div>"Science is about questioning the status quo. Questioning authority". </div>
<div>In the absence of evidence, opinion is indistinguishable from prejudice.
<p align=right>[http://www.theregister.co.uk/2011/11/29/sas_versus_world_programming/|The start of some sanity?]</p></div>
</font>
</div></div>
946545
946583