Normalize Windows Path Names

Discussion in 'Ruby' started by rtilley, Apr 6, 2006.

  1. rtilley

    rtilley Guest

    Is there a way to normalize pathnames? On Windows, many system calls
    return a windows path that contains back slashes like this:

    C:\windows\system32

    I'd prefer to have forward slashes since they are easier to work with
    like this:

    C:/windows/system32

    Windows will accept either slash. What is the best way for Ruby to
    convert to normal slashes?

    Thank you,
    Brad
    rtilley, Apr 6, 2006
    #1
    1. Advertising

  2. rtilley wrote:
    > Is there a way to normalize pathnames? On Windows, many system calls
    > return a windows path that contains back slashes like this:
    >
    > C:\windows\system32
    >
    > I'd prefer to have forward slashes since they are easier to work with
    > like this:
    >
    > C:/windows/system32
    >
    > Windows will accept either slash. What is the best way for Ruby to
    > convert to normal slashes?


    See String#tr and String#tr!

    "C:\\foo\\bar".tr("\\", '/') # C:/foo/bar

    Regards,

    Dan
    Daniel Berger, Apr 7, 2006
    #2
    1. Advertising

  3. rtilley

    rtilley Guest

    Daniel Berger wrote:
    > rtilley wrote:
    >
    >>Is there a way to normalize pathnames? On Windows, many system calls
    >>return a windows path that contains back slashes like this:
    >>
    >>C:\windows\system32
    >>
    >>I'd prefer to have forward slashes since they are easier to work with
    >>like this:
    >>
    >>C:/windows/system32
    >>
    >>Windows will accept either slash. What is the best way for Ruby to
    >>convert to normal slashes?

    >
    >
    > See String#tr and String#tr!
    >
    > "C:\\foo\\bar".tr("\\", '/') # C:/foo/bar
    >
    > Regards,
    >
    > Dan


    Thanks Dan! That's great.
    rtilley, Apr 7, 2006
    #3
    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. arnold
    Replies:
    1
    Views:
    598
    arnold
    Mar 5, 2006
  2. Christos TZOTZIOY Georgiou

    unicodedata . normalize (NFD - NFC) inconsistency

    Christos TZOTZIOY Georgiou, Nov 8, 2004, in forum: Python
    Replies:
    3
    Views:
    880
    Christos TZOTZIOY Georgiou
    Nov 10, 2004
  3. AndyL
    Replies:
    6
    Views:
    426
    John Machin
    May 25, 2006
  4. =?iso-8859-1?B?TWF0dGlhcyBCcuRuZHN0cvZt?=

    Vector, matrix, normalize, rotate. What package?

    =?iso-8859-1?B?TWF0dGlhcyBCcuRuZHN0cvZt?=, Feb 27, 2007, in forum: Python
    Replies:
    5
    Views:
    6,305
  5. Mike
    Replies:
    0
    Views:
    409
Loading...

Share This Page