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 [EMAIL PROTECTED]; #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 [EMAIL PROTECTED];
$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
[EMAIL PROTECTED];
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
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/