Perl Monk, Perl Meditation | |
PerlMonks |
Re: Quickest way to get a list of all folders in a directoryby Clarendon4 (Acolyte) |
on Aug 17, 2009 at 08:59 UTC ( [id://789101]=note: print w/replies, xml ) | Need Help?? |
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.
In Section
Seekers of Perl Wisdom
|
|