Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Invalid top directory at d:\perl\lib\file\find.pm line 562

Reply
Thread Tools

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

 
 
Perler
Guest
Posts: n/a
 
      09-27-2007
Hi, i am using the following script to find a file entered by a user.

use Win32:riveInfo;
use File::Find;

my @drives = Win32:riveInfo:rivesInUse(); #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:riveInfo:riveType($drives[$i-1]);
if($type==3)#fixed drives
{
$d[$i-1]=$drives[$i-1].":"."\\","\\";
}
}

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

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

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
{
$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)
{
print "\n File Found",$path;
}



}

}


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"

Pls help me.


Thanks in advances

 
Reply With Quote
 
 
 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      09-27-2007
On Sep 27, 1:29 am, (E-Mail Removed) (Perler) wrote:
> [a multipost]


Please don't multipost.


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)

 
Reply With Quote
 
 
 
 
Martijn Lievaart
Guest
Posts: n/a
 
      09-27-2007
On Thu, 27 Sep 2007 09:02:29 +0000, Perler wrote:

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


Not tested, just some general comments about the code.

use strict;
use warnings;

Don't ever post a script here without strict and warnings enabled. You'll
find a lot of errors yourself if you enable them, no need to ask the
group to solve problems you could have solved yourself.

>
> use Win32:riveInfo;
> use File::Find;
>
> my @drives = Win32:riveInfo:rivesInUse(); #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:riveInfo:riveType($drives[$i-1]); if($type==3)#fixed
> drives
> {
> $d[$i-1]=$drives[$i-1].":"."\\","\\";
> }
> }


Ouch. What is that comma there? ^^^^.

Also, array @d will have "holes" as you don't assign the entries that are
not corresponding to a fixed drive.

The concatenation is also not elegant, ":"."\\" is better written as ":\
\".

I would try something like:

my @d;
for (@drives) {
push @d, "$_:\\"
if Win32:riveInfo:riveType($_) == 3;
}

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


Very bad variable name. Also missing 'my'.

>
> my @t=split(/\./,$temp); #Split the filename to get the extension
>
> my $cnt=@t;
>
> $f=".".$t[$cnt-1]; #Append "." and extension


Very bad variable name.

my $extension = $tmp;
$extension =~ s/.*\././;

>
> find(\&cleanup,@d); #standard file find function
>
> sub cleanup {
>
> if ((/$f/))#$f= appneding "." and file extension for eg:
> $f=.pl,$f=.txt


I don't grok this comment at all. Also,m this will produce false
positives. ITYM

if (/$f$/)

> {
> $path=$File::Find::name; #$path will contain the
> complete
> path of a file
>
> @p=split(/\//,$path); #just get the file name


The filename is also in $_ here, no need to get it this way.

>
> $cnt=@p;
> if($p[$cnt-1] eq $temp)
> {
> print "\n File Found",$path;
> }
>
>
>
> }
>
> }
>
>
> 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"
>


First make it run with strict and warnings enabled. Than put in some
print statements to confirm the variables contain what you think they
contain.

Also, this can be done much more simple. No need to check the extension.
It's part of the filename. Completely redundant. Get rid of all the
extension handling stuff. Something along these lines (untested):



use strict;
use warnings;

use Win32:riveInfo;
use File::Find;

if (@ARGV != 1) {
die "usage:...";
}

my $file2find = $ARGV[0];

my @drives;
for (Win32:riveInfo:rivesInUse()) {
push @drives, "$_:\\"
if Win32:riveInfo:riveType($_) == 3;
}

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

sub cleanup {
if ($_ eq $file2find) {
my $path=$File::Find::name;
print "File Found: $path\n";
}
}


HTH,
M4
 
Reply With Quote
 
Perler
Guest
Posts: n/a
 
      09-28-2007
On Sep 27, 2:45 pm, (E-Mail Removed) wrote:
> On Sep 27, 1:29 am, (E-Mail Removed) (Perler) wrote:
>
> > [a multipost]

>
> Please don't multipost.
>
> --
> The best way to get a good answer is to ask a good question.
> David Filmer (http://DavidFilmer.com)


I am really sorry for multiposting but i was getting an error of mail
delievery failure many times.
Wont happen again.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Study material for 70-562 Microsoft Certification Shilpa Ginode MCTS 28 02-22-2010 03:21 AM
70-528 or 70-562 jack MCTS 1 02-14-2009 04:17 PM
study material for mcts 70-562 jack MCTS 1 01-09-2009 07:38 PM
RE: Study material for 70-562 Microsoft Certification kemp MCTS 0 12-23-2008 02:39 PM
Product of Visual Studio 2008 needed for 70-536, 70-562 and 70-564 Benjamin Rogers MCTS 1 11-26-2008 05:54 PM



Advertisments