Ed Panni wrote:
>
> I was wondering if there is a quicker way of getting a directory listing
> from a disk. I am currently doing the following but it takes a bit of
> time if I happen to have to search multiple 250Gb drives.
>
> # Trying to locate tests on the systems disks and establish paths to
> them";
>
> $i = c d e;
>
>  @array = "";
>
>  foreach $i (split/ /,$disk) {
>
>     print "\nChecking $i: for the tests.....";
>
>     @array1= `dir $i:\\ /B /S`;
>
>     # Establish a count of how big the array is for stepping through the
>     # array later to find the .exe file
>
>     $lineC = @array1;
>
>      # append the array if more than one disk is selected
>
>      push(@array, @array1);
>   }

Hi Ed.

It's hard to know exactly what you're doing, but on a Windows system it's far
quicker to use the 'dir' command than calling readdir() in native Perl. It looks
like you may be intrested only in the .exe files, in which case it may be quicker to let 'dir' find them for you. Also, unless you really need to process
each drive separately, you can do the whole thing in one command line:

  use strict;
  use warnings;

  my @drives = qw/C D E/;
  my $command = "dir /b /s " . join ';', map "$_:\\*.exe", @drives;
  print $command;

  chomp (my @files = qx($command));
  chomp @files;
  print "$_\n" foreach @files;

qx() is the same thing as backticks. This takes 90 seconds to run on 500GB of
drive space on my system.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to