|
|
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
|
|
0
|
|
|
|
Reply
|
ramon (1469)
|
5/3/2007 1:34:57 AM |
|
Ramon F Herrera <ramon@conexus.net> 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/
|
|
0
|
|
|
|
Reply
|
comphelp (341)
|
5/3/2007 2:35:23 AM
|
|
On May 2, 9:35 pm, comph...@toddh.net (Todd H.) wrote:
> Ramon F Herrera <r...@conexus.net> 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
|
|
0
|
|
|
|
Reply
|
ramon (1469)
|
5/3/2007 2:54:37 AM
|
|
In article <1178160877.603439.246150@h2g2000hsg.googlegroups.com>, Ramon F
Herrera <ramon@conexus.net> 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
|
|
0
|
|
|
|
Reply
|
haberg627 (1617)
|
5/5/2007 12:43:48 PM
|
|
|
3 Replies
46 Views
(page loaded in 0.07 seconds)
|
|
|
|
|
|
|
|
|