Re: Invalid top directory at d:\perl\lib\file\find.pm line 562



Perler wrote:
Hi,

Hello,

i am using the following script to find a file entered by a user.

use warnings;
use strict;

use Win32::DriveInfo;
use File::Find;

my @drives = Win32::DriveInfo::DrivesInUse(); #Get the drives on a
Machine

my $cnt=@drives; #Number of Drives

my $i=$cnt; #Counter assignment

#The following loop appends "/" to the drive letter
#if the drive is a fixed drive.

for($i;$i>0;$i--)
{
$type=Win32::DriveInfo::DriveType($drives[$i-1]);
if($type==3)#fixed drives
{
$d[$i-1]=$drives[$i-1].":"."\\","\\";

Your comment above says 'appends "/" to the drive letter' but it looks like you are appending ':\\'?


}
}

Or more simply:

my @d = map 3 == Win32::DriveInfo::DriveType( $_ )
? "$_:\\\\"
: (),
Win32::DriveInfo::DrivesInUse();


$temp=$ARGV[0]; #store filename to be found

my @t=split(/\./,$temp); #Split the filename to get the extension

perldoc File::Basename


my $cnt=@t;

$f=".".$t[$cnt-1]; #Append "." and extension

find(\&cleanup,@d); #standard file find function

sub cleanup {

if ((/$f/))#$f= appneding "." and file extension for eg:
$f=.pl,$f=.txt

In the split above you are escaping the period but here you are not so it will match any character and the pattern is not anchored so it can match anywhere in the string, not just at the end.
Why test for the extension *and* compare the complete file name?


{
$path=$File::Find::name; #$path will contain the complete
path of a file

@p=split(/\//,$path); #just get the file name

$cnt=@p;
if($p[$cnt-1] eq $temp)

Why not just use the file name provided in the $_ variable (like you are doing with the file extension test above?)


{
print "\n File Found",$path;
}
}
}

Or more simply:

my $temp = $ARGV[ 0 ]; #store filename to be found
find sub {
print "File Found $File::Find::name\n" if $_ eq $temp
}, @d;


If i run this script i am getting the error as "Invalid top directory
at d:\perl\lib\file\find.pm line 562, <DATA> line164"

This script doesn't have 562 lines and nowhere are you using a DATA filehandle so it is hard to say why the error message is appearing.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.



Relevant Pages

  • Client Side Extensions (Server 2008 Question)
    ... I downloaded the client side extensions for Windows XP and have been testing ... at all upgraded to server 2008 to use the client side extension features ... like preferences (map drives, shortcuts etc) ...
    (microsoft.public.windows.server.general)
  • Re: What cables do think Ill need?
    ... and a 24 pin MB power extension cable. ... interior clean visually, and for airflow. ... I also recommend mounting the hard drives vertically in the ... in the middle drive bay. ...
    (alt.comp.hardware.pc-homebuilt)
  • Re: What cables do think Ill need?
    ... and a 24 pin MB power extension cable. ... interior clean visually, and for airflow. ... I also recommend mounting the hard drives vertically in the ... in the middle drive bay. ...
    (alt.comp.hardware.pc-homebuilt)
  • Re: Client Side Extensions (Server 2008 Question)
    ... Also what would be the best way to deploy the client side extensions since ... features like preferences (map drives, ... I notice when using the map drive extension that if you give ...
    (microsoft.public.windows.server.general)
  • Re: UNKNOWN SYSTEM FILE?
    ... They may have an extension that you are not seeing. ... > Move them to a different hard drive/partition for a few days to see ...
    (microsoft.public.windowsxp.basics)