in reply to Two questions (two birds with one stone)
$File::Find::prune = 1, return if $File::Find::name =~ m{^.:/System Volume Information$};
As an example, the code below finds the first file over 100MB in size, and then gets out quickly. On my NTFS volume (19489 files), $extras was just 19. Uncomment the line to test the goto version.
use File::Find; my @drives = ( 'c:/', 'd:/' ); my $kill_find = 0; my $extras = 0; find( sub { $extras++ if $kill_find; $File::Find::prune = 1, return if $File::Find::name =~ m{^.:/System Volume Information$}; $File::Find::prune = 1, return if $kill_find; return if -d $_; # print "$File::Find::name\n" and goto End_F if -s(_) > 100_000_000; print "$File::Find::name\n" and $kill_find=1 if -s(_) > 100_000_000; }, @drives ); End_F: print "Extra files or directories checked by this method: $extras\n";
Meditation on skiping to the next dir using File::Find; may provide further enlightenment.
Lastly, GetVolumeInformation does not return 'Local Disk' unless that happens to be the volume name you gave your disk when you formatted it. FWIW, here is how I would write the code you posted:
#!/usr/bin/perl -w use strict; use warnings 'all'; use File::Find; use Win32API::File qw( :Func :DRIVE_ ); my @drives = map { tr{\\}{/}s; $_ } grep { GetDriveType($_) == DRIVE_FIXED } getLogicalDrives(); find( sub { $File::Find::prune = 1, return if $File::Find::name =~ m{^.:/System Volume Information$}; return unless /^VCVARS32\.BAT$/i; for ($File::Find::name) { # s{\/}{}; # tr{/}{\\}; print "$_\n"; } }, @drives );
|
|---|