Problem using find on win32

Discussion in 'Perl Misc' started by Mikael Petterson, Feb 25, 2008.

  1. 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, Feb 25, 2008
    #1
    1. Advertising

  2. Mikael Petterson

    Klaus Guest

    On Feb 25, 4:48 pm, Mikael Petterson <>
    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
     
    Klaus, Feb 25, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Java and Swing
    Replies:
    1
    Views:
    706
    Chris Lambacher
    Oct 24, 2005
  2. Tim Golden
    Replies:
    0
    Views:
    462
    Tim Golden
    Oct 21, 2005
  3. Wybo Dekker
    Replies:
    1
    Views:
    396
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    437
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    863
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page