Problem using find on win32

M

Mikael Petterson

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: (e-mail address removed)
 
K

Klaus

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top