Perl/DOS how do i check if directories are equivalent ...

Discussion in 'Perl Misc' started by Random Task, Aug 8, 2005.

  1. Random Task

    Random Task Guest

    Hi quick question

    I have two paths say:

    C:\pRoGram Files\Monkey Boy\\\\\\
    C:\PRoGraM Files\Monkey BOY

    Is there a quick way of telling the directories are the same?

    Jim
     
    Random Task, Aug 8, 2005
    #1
    1. Advertising

  2. Random Task <> writes:

    > I have two paths say:
    >
    > C:\pRoGram Files\Monkey Boy\\\\\\
    > C:\PRoGraM Files\Monkey BOY
    >
    > Is there a quick way of telling the directories are the same?


    I'm not certain if it would work on Windows, or with directories, but the
    first thing I'd try is doing a stat() on both paths and comparing the inodes.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Aug 8, 2005
    #2
    1. Advertising

  3. Random Task

    Random Task Guest

    Sherm Pendley wrote:
    > Random Task <> writes:
    >
    >
    >>I have two paths say:
    >>
    >>C:\pRoGram Files\Monkey Boy\\\\\\
    >>C:\PRoGraM Files\Monkey BOY
    >>
    >>Is there a quick way of telling the directories are the same?

    >
    >
    > I'm not certain if it would work on Windows, or with directories, but the
    > first thing I'd try is doing a stat() on both paths and comparing the inodes.
    >
    > sherm--
    >


    Doesn't seem to work on windows :-(

    I guess i am stuck using:
    - lc
    - compare length
    - remove trailing \'s until strlen = or no \'s
    - compare when equal len and no \'s
     
    Random Task, Aug 8, 2005
    #3
  4. Random Task

    Random Task Guest

    Sherm Pendley wrote:
    > Random Task <> writes:
    >
    >
    >>I have two paths say:
    >>
    >>C:\pRoGram Files\Monkey Boy\\\\\\
    >>C:\PRoGraM Files\Monkey BOY
    >>
    >>Is there a quick way of telling the directories are the same?

    >
    >
    > I'm not certain if it would work on Windows, or with directories, but the
    > first thing I'd try is doing a stat() on both paths and comparing the inodes.
    >
    > sherm--
    >

    here's what i did to get around this ... seems to work ok at first
    glance :)

    my $tmp = lc $dir1;
    my $tmp2 = lc $dir2;


    if ($tmp eq $tmp2)
    {
    &somemagic();
    }
    elsif ( length($tmp) < length($tmp2))
    {
    $tmp=~s/\\/\\\\/g;
    $tmp2 =~ s/$tmp//g;
    $tmp2 =~ s/\\//g;
    if ($tmp2 eq "")
    {
    &somemagic();
    }
    }
    else #if (length($tmp) > length($tmp2))
    {
    $tmp2=~s/\\/\\\\/g;
    $tmp =~ s/$tmp2//g;
    $tmp =~ s/\\//g;
    if ($tmp eq "")
    {
    &somemagic();
    }
    }
     
    Random Task, Aug 8, 2005
    #4
  5. Random Task

    Thomas Kratz Guest

    Random Task wrote:
    > Hi quick question
    >
    > I have two paths say:
    >
    > C:\pRoGram Files\Monkey Boy\\\\\\
    > C:\PRoGraM Files\Monkey BOY
    >
    > Is there a quick way of telling the directories are the same?
    >
    > Jim


    Here's one way:

    use strict;
    use warnings;

    use File::Spec::Functions;

    my $p1 = 'C:\pRoGram Files\Monkey Boy\\\\\\';
    my $p2 = 'C:\PRoGraM Files\Monkey BOY';

    print "YEP!\n" if canonpath(uc($p1)) eq canonpath(uc($p2));


    Thomas

    --
    $/=$,,$_=<DATA>,s,(.*),$1,see;__END__
    s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
    $_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
    '%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
    print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
     
    Thomas Kratz, Aug 8, 2005
    #5
  6. Random Task

    Damian James Guest

    On Mon, 08 Aug 2005 11:25:46 -0400, Random Task said:
    > I have two paths say:
    >
    > C:\pRoGram Files\Monkey Boy\\\\\\
    > C:\PRoGraM Files\Monkey BOY
    >
    > Is there a quick way of telling the directories are the same?


    One quick and messy way I have resorted to in the past to match
    directory names in a case insensitive way is to turn the path
    into a glob pattern:
    (untested)

    lc $name;
    $name =~ s/[a-z]/"[$&".uc($&)."]"/eg;
    my $file = glob $name;

    or somesuch.

    You'd probably store the results of the glob() as hash keys,
    if you wished to eliminate duplicates.

    --Damian
     
    Damian James, Aug 9, 2005
    #6
    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. Ben Fairbank
    Replies:
    2
    Views:
    5,460
  2. john san
    Replies:
    19
    Views:
    743
    Diez B. Roggisch
    Feb 18, 2005
  3. Replies:
    5
    Views:
    391
  4. tomhr
    Replies:
    27
    Views:
    1,421
    Mike Wahler
    Jan 12, 2006
  5. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    281
    Michele Dondi
    Jan 22, 2004
Loading...

Share This Page