Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
But I have 2 use my @files = `attrib /s c:\\*`; my $n = scalar @files;

I did warn you against loading the entire list into perl. It really slows things down.

as without it says that wc is an unrecognised command

There are various cures for that possible:

  • Download yourself a copy of wc.exe for Windows.

    It is easy to find and its a program that is just to useful to be without.

  • Use attrib /s c:\* | perl -nE"}{say $."

    It is a poor substitute but works for this use.

  • Use the suggestion by cdarke.

    Simple and effective.

But I remembered a faster method. This uses the Windows Script Host to do the donkey work via Win32::OLE and runs 3 times faster on my machine.

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:

#! 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]

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

In reply to Re^5: fast count files by BrowserUk
in thread fast count files by gautamparimoo

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (12)
    As of 2015-12-01 09:02 GMT
    Find Nodes?
      Voting Booth?

      What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

      Results (797 votes), past polls