From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Daniel Burgaud Sent: 13 March 2012 22:53 To: Perl-Win32-Users Subject: directory listing of "Computer" on win32
> Hi All, > > I am clueless how to do a directory list starting at the very root "Computer" > which includes all drives. > > What I am doing to get a directory tree is this: > my $directory = ""; > opendir DIR, $directory; > my @files = readdir DIR; > closedir DIR; > > But it only start at one drive - not all drives. I am missing out on where to > start the initial directory. > > My main goal is to get all the drives on my computer, so I can do a directory > tree on those drives. To get the logical drives you can use GetLogicalDriveStrings in Win32API::File (see the documentation for that module). You will probably need to stat them to make sure that they have a valid file system. I would use File::Find rather than opendir/readdir to traverse the files and directories on a drive. Take a look at the documentation for that module as well. For example... use strict; use warnings; use Win32API::File qw{GetLogicalDriveStrings}; use File::Find; my $dstring; my $olen = GetLogicalDriveStrings(26*4+1, $dstring); my @drives = map {s|\\|/|g; $_} grep {stat($_)} split "\000", $dstring; print "Drives [@drives]\n"; find(sub { print "$File::Find::name\n"; }, @drives); HTH -- Brian Raven Please consider the environment before printing this e-mail. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs