Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Quickest way to get a list of all folders in a directory

by Clarendon4 (Acolyte)
on Aug 17, 2009 at 08:59 UTC ( [id://789101]=note: print w/replies, xml ) Need Help??


in reply to Quickest way to get a list of all folders in a directory

If you are interested in the actual '*quickest* way to get a list of all folders in a directory' on Windows then you'll need either an XS extension or external C program *.

Why? Because the pure Perl code typically used to do this task of opendir/readdir/-d will make unnecesary extra system calls. At the Win32 API level Perl's readdir is done by FindNextFile() which returns a WIN32_FIND_DATA structure that contains whether the returned file is a directory. Unfortunately this info is not kept so you must then stat() it to test if it's a directory. This extra work can amount to a significant overhead.

And also remember to:  ${^WIN32_SLOPPY_STAT} = 1; to avoid more extraneous system calls (unless you are actually interested in the link count of stat'd files!)

* I use qfind to efficiently find all the files in a directory. Modifying it to do what you want is left as an exercise :-) You can find it at http://backpan.perl.org/authors/id/A/AD/ADAVIES/qfind.c-1.06

alex.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://789101]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-26 05:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found