Problem using find on win32

  • Follow


Hi,

I am trying to find the following file ( where version number can vary)
org.eclipse.equinox.lanucher_x.x.x.jar in "C:\\Tools\\SDS\\plugins\\"


sub equinox (){
 $jar = $File::Find::name if /\Aorg\.eclipse\.equinox\.launcher_.*\.jar\z/;
}

my $equinoxDir = "C:\\Tools\\SDS\\plugins\\

find (\&equinox,$equinoxDir);


I can see that the path for files & directories found using find becomes:

/mydir/file1.txt
/mydir/file2.txt

and so on.

So the full path becomes:

C:\\Tools\\SDS\\plugins\\/mydir 

which does not work.

How can make paths be the same.

-- 
Mikael Petterson 
Software Designer 
 
 
Ericsson AB, Stockholm, Sweden 
Visiting address: Isafjordsgatan 15, Kista 
Phone: +46 70 2673044  
E-mail: mikael.petterson@ericsson.com  

0
Reply Mikael 2/25/2008 3:48:16 PM

On Feb 25, 4:48 pm, Mikael Petterson <mikael.petter...@ericsson.com>
wrote:
> my $equinoxDir = "C:\\Tools\\SDS\\plugins\\

I would recommend to use forward slashes (/) instead of back slashes
(\) wherever possible.

my $equinoxDir = "C:/Tools/SDS/plugins/";

It's easier on the eyes (avoids "\\", "leaning toothpicks") and it
works even on Windows (unless you shell out to the command line prompt
with system(), in which case you are forced to use back slashes)

> find (\&equinox,$equinoxDir);
>
> I can see that the path for files & directories found using find becomes:
>
> /mydir/file1.txt
> /mydir/file2.txt
>
> and so on.

I observe: File::find has returned forward slashes.

> So the full path becomes:
>
> C:\\Tools\\SDS\\plugins\\/mydir
>
> which does not work.

You have a mix of forward and backward slashes, which might be the
reason for your problem.

If you use forward slashes to start with, your full path will be:
$fullpath = "C:/Tools/SDS/plugins//mydir";

Notice that there is only one type of slash (forward slash).
The double forward slash between "plugins" and "mydir" gets
automatically resolved into a single slash, no need to resolve that,
really. This should work perfectly, even on Windows.

However, should you wish to resolve it for other reasons, or just
because it looks better, then you could use:

$fullpath =~ s{/+}{/}g;

--
Klaus
0
Reply Klaus 2/25/2008 4:30:23 PM


1 Replies
81 Views

(page loaded in 0.035 seconds)

Similiar Articles:













7/5/2012 11:03:47 AM


Reply: