Is that Windows? It can't work: "/" is the root of the current drive. What you should do, is pass a list of all the roots of all drives to find(). Looking up some Win32 API docs... I found this function:
use Win32::API; my $GetLogicalDriveStrings = new Win32::API(kernel32 => GetLogicalDriv +eStrings => ['N', 'P'], 'N'); my $drives = "\0" x 4000; my @drives; if($GetLogicalDriveStrings->Call(length $drives, $drives)) { @drives = split /\0+/, $drives; }
which produces a nice list of drive root directories, with a trailing backslash. Nice.

You might want to skip the floppies, though... 'A:' and 'B:'. There's an API call to recognize ejectable drives, but I'll skip that for now.

Now we have a list of roots to scan into, we still have to actually do it:

use File::Find; my %results; find sub { -f and push @{$results{$File::Find::dir}}, $_ if -e && /^pe +rl/ }, @drives; use Data::Dumper; print Dumper \%results;
The result of everything found is in a hash. The directory itself will be the hash key, the files found will be in the array that is the hash value.

update: warning: this takes ages for me to do its job. Don't use it on a regular basis. :)


In reply to Re: Using File::Find to find drive (Win32) by bart
in thread Using File::Find to find drive (Win32) by FireBird34

Title:
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, details, 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, summary, 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.