How to convert a directory path to canonical form? - Unix

This is a discussion on How to convert a directory path to canonical form? - Unix ; My application accepts a directory path as its argument. I have no trouble dealing with a standard path with slashes. However, when the user types one of the other path specs (those that begin with a period) the program breaks. ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: How to convert a directory path to canonical form?

  1. How to convert a directory path to canonical form?


    My application accepts a directory path as its argument. I have no
    trouble dealing with a standard path with slashes. However, when the
    user types one of the other path specs (those that begin with a
    period) the program breaks.

    Is there a function that will convert, for instance "." into "/home/
    ramon/src"?

    TIA,

    -Ramon


  2. Re: How to convert a directory path to canonical form?

    Ramon F Herrera writes:

    > My application accepts a directory path as its argument. I have no
    > trouble dealing with a standard path with slashes. However, when the
    > user types one of the other path specs (those that begin with a
    > period) the program breaks.
    >
    > Is there a function that will convert, for instance "." into "/home/
    > ramon/src"?


    The $PWD environment variable may be of assistance to you.
    Concatenate it appropriately with the input argument and enjoy.

    You may wish to post the relevant code that might be handling that
    argument and an indication of which line where it breaks. I suspect
    that there's a way to write your program that wouldn't require such
    gymnastics.

    --
    Todd H.
    http://www.toddh.net/

  3. Re: How to convert a directory path to canonical form?

    On May 2, 9:35 pm, comph...@toddh.net (Todd H.) wrote:
    > Ramon F Herrera writes:
    >
    > > My application accepts a directory path as its argument. I have no
    > > trouble dealing with a standard path with slashes. However, when the
    > > user types one of the other path specs (those that begin with a
    > > period) the program breaks.

    >
    > > Is there a function that will convert, for instance "." into "/home/
    > > ramon/src"?

    >
    > The $PWD environment variable may be of assistance to you.
    > Concatenate it appropriately with the input argument and enjoy.
    >
    > You may wish to post the relevant code that might be handling that
    > argument and an indication of which line where it breaks. I suspect
    > that there's a way to write your program that wouldn't require such
    > gymnastics.
    >
    > --
    > Todd H.http://www.toddh.net/


    Thanks Todd:

    My program takes a path like:

    /home/ramon/src/devel/

    and breaks it into:

    (1) /home/ramon/src
    and
    (2) devel/

    I know exaclty why it breaks: because I haven't implemented the "dot"
    cases. I am also not sure what is the proper way to handle cases
    like:

    /home/ramon/src/devel////////

    I just didn't want to reinvent the wheel. The $PWD advice is good,
    and I am already using it in some of my programs.

    I will look into "basename" and "dirname" as well.

    Thanks again,

    -Ramon



  4. Re: How to convert a directory path to canonical form?

    In article <1178160877.603439.246150@h2g2000hsg.googlegroups.c om>, Ramon F
    Herrera wrote:

    > > > My application accepts a directory path as its argument. I have no
    > > > trouble dealing with a standard path with slashes. However, when the
    > > > user types one of the other path specs (those that begin with a
    > > > period) the program breaks.


    > I know exaclty why it breaks: because I haven't implemented the "dot"
    > cases. I am also not sure what is the proper way to handle cases
    > like:
    >
    > /home/ramon/src/devel////////
    >
    > I just didn't want to reinvent the wheel.


    This is described in the 'bash' manual page, the section "COMMAND EXECUTION".

    Hans Aberg

+ Reply to Thread