Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Win32 Recursive Directory Listing

by silent11 (Vicar)
on Apr 09, 2002 at 21:33 UTC ( [id://157865]=note: print w/replies, xml ) Need Help??


in reply to Win32 Recursive Directory Listing

We all know that there is ' more than one way to do it ', well can some one tell me why 'my' way doesn't work? I'm courious to know. Thanks in advance!
use strict; my @dirs = system(dir /b /s); for (@dirs) {print;}
-Silent11

Replies are listed 'Best First'.
Re: Re: Win32 Recursive Directory Listing
by VSarkiss (Monsignor) on Apr 09, 2002 at 23:14 UTC

    The system function returns the exit status code of the program, not its output. See system and the qx or backticks operator. More importantly, your code will only run on Win32, whereas File::Find will work on Unix and related systems as well.

      There is an issue with File::Find (and hand-rolled solutions too) on win32 when working with mapped file systems. It will stat every file to determine whether it is a directory and needs to be recursed into. Each stat requires a server round-trip which can be slow.

      If you call the DOS function you can do the whole thing in one hit. If you are certain the script will never be needed on a non-win32 system there is no issue with portability.

      I was doing something similar a while back, and reduced the run time from several hours to under ten minutes.

      -- iakobski

Re: Re: Win32 Recursive Directory Listing
by strat (Canon) on Apr 10, 2002 at 11:48 UTC
    You might better want to use backticks or pipe-open instead of system to get the output on STDOUT...

    e.g backticks

    my @files = `dir /b /s`; chomp(@files);
    or with pipe-open:
    unless (open (DIR, "dir /b /s |")){ die "Error: couldn't execute dir-command: $!\n"; } else { my @files = <DIR>; close (DIR); chomp(@files); }

    Best regards,
    perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-04-19 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found