Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How Does One Discover the Full Path Name of the Current Directory?

Reply
Thread Tools

How Does One Discover the Full Path Name of the Current Directory?

 
 
kvnsmnsn@hotmail.com
Guest
Posts: n/a
 
      05-11-2007
I've written a piece of code that interfaces with Postgres. It needs
to write a Postgres table to disk, which it does with the <COPY> com-
mand. That command requires the absolute file name of the file being
written to. Right now I've got it hard coded to the exact location
where I want it, but that's not very portable. Is there some way in C
to retrieve the absolute path name of the current directory, so that I
could use that in my code and therefore have my code function right no
matter where it's executed? Any information on this would be greatly
appreciated.

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_

 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      05-11-2007
In article <(E-Mail Removed). com>,
<(E-Mail Removed)> wrote:

>I've written a piece of code that interfaces with Postgres. It needs
>to write a Postgres table to disk, which it does with the <COPY> com-
>mand. That command requires the absolute file name of the file being
>written to. Right now I've got it hard coded to the exact location
>where I want it, but that's not very portable. Is there some way in C
>to retrieve the absolute path name of the current directory, so that I
>could use that in my code and therefore have my code function right no
>matter where it's executed? Any information on this would be greatly
>appreciated.


There's no portable way to do this in standard C: in fact, C itself
doesn't know anything at all about directories. But all operating
systems provide a way to do it. For example, unix systems have
getcwd() ("get current working directory") which is declared in
<unistd.h>.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
 
Reply With Quote
 
 
 
 
kvnsmnsn@hotmail.com
Guest
Posts: n/a
 
      05-11-2007
Thanks!

 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      05-11-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) (Richard Tobin) wrote:

> In article <(E-Mail Removed). com>,
> <(E-Mail Removed)> wrote:
>
> >Is there some way in C to retrieve the absolute path name of the
> >current directory,


> There's no portable way to do this in standard C: in fact, C itself
> doesn't know anything at all about directories. But all operating
> systems provide a way to do it.


All operating systems _where this is possible in the first place_. It is
not always possible; for example, under very early versions of MS-DOS,
there was no such thing as a directory. All common modern desktop OSes
have them, but I would not be surprised at all to learn of embedded ones
that have files, but no directories, and therefore no path names,
absolute or relative.

Richard
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      05-11-2007
Richard Bos a écrit :
> (E-Mail Removed) (Richard Tobin) wrote:
>
>
>>In article <(E-Mail Removed). com>,
>> <(E-Mail Removed)> wrote:
>>
>>
>>>Is there some way in C to retrieve the absolute path name of the
>>>current directory,

>
>
>>There's no portable way to do this in standard C: in fact, C itself
>>doesn't know anything at all about directories. But all operating
>>systems provide a way to do it.

>
>
> All operating systems _where this is possible in the first place_. It is
> not always possible; for example, under very early versions of MS-DOS,
> there was no such thing as a directory. All common modern desktop OSes
> have them, but I would not be surprised at all to learn of embedded ones
> that have files, but no directories, and therefore no path names,
> absolute or relative.
>
> Richard


Nobody cares about those systems. If you would have read what the
original poster wrote, you would have seen the first sentence:

"I've written a piece of code that interfaces with Postgres."

It would be astounding that Postgres runs in an embedded OS with
no directories or under "early MSDOS" isn't it?

But at each question we have to know apparently how we make the
program portable to MSDOS systems without directories, or whatever.

Living in the past is a favorite passtime of people in this group
apparently.
 
Reply With Quote
 
Chris Dollin
Guest
Posts: n/a
 
      05-11-2007
jacob navia wrote:

> Richard Bos a écrit :
>> (E-Mail Removed) (Richard Tobin) wrote:


>> All operating systems _where this is possible in the first place_. It is
>> not always possible; for example, under very early versions of MS-DOS,
>> there was no such thing as a directory. All common modern desktop OSes
>> have them, but I would not be surprised at all to learn of embedded ones
>> that have files, but no directories, and therefore no path names,
>> absolute or relative.
>>
>> Richard

>
> Nobody cares about those systems.


I bet that's not true.

> If you would have read what the
> original poster wrote, you would have seen the first sentence:
>
> "I've written a piece of code that interfaces with Postgres."
>
> It would be astounding that Postgres runs in an embedded OS with
> no directories or under "early MSDOS" isn't it?


Doesn't matter -- /that/ question had already been answered.

> But at each question we have to know apparently how we make the
> program portable to MSDOS systems without directories, or whatever.


I think you're misreading the intention of the answer.

> Living in the past is a favorite passtime of people in this group
> apparently.


Some people have made money from "Living in the Past". It's not to
be sneezed at.

--
"Never ask that question!" Ambassador Kosh, /Babylon 5/

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      05-11-2007
Chris Dollin <(E-Mail Removed)> wrote:

> jacob navia wrote:
>
> > Richard Bos a écrit :
> >> (E-Mail Removed) (Richard Tobin) wrote:

>
> >> All operating systems _where this is possible in the first place_. It is
> >> not always possible; for example, under very early versions of MS-DOS,
> >> there was no such thing as a directory. All common modern desktop OSes
> >> have them, but I would not be surprised at all to learn of embedded ones
> >> that have files, but no directories, and therefore no path names,
> >> absolute or relative.

> >
> > Nobody cares about those systems.

>
> I bet that's not true.


Well, nobody who is anybody cares: obviously, because jacob does not
care, and jacob is the only person who is anybody, and his (lack of)
experience defines the universe.

> > But at each question we have to know apparently how we make the
> > program portable to MSDOS systems without directories, or whatever.

>
> I think you're misreading the intention of the answer.


Quite.

> > Living in the past is a favorite passtime of people in this group
> > apparently.

>
> Some people have made money from "Living in the Past". It's not to
> be sneezed at.


Jethro Tull, for example .

Richard
 
Reply With Quote
 
Chris Dollin
Guest
Posts: n/a
 
      05-11-2007
Richard Bos wrote:

>> Some people have made money from "Living in the Past". It's not to
>> be sneezed at.

>
> Jethro Tull, for example .


Shh. Someone might still fall into the trap.

--
"Who do you serve, and who do you trust?" /Crusade/

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      05-11-2007
In article <(E-Mail Removed)4all.nl>,
Richard Bos <(E-Mail Removed)> wrote:

>> >Is there some way in C to retrieve the absolute path name of the
>> >current directory,


>> There's no portable way to do this in standard C: in fact, C itself
>> doesn't know anything at all about directories. But all operating
>> systems provide a way to do it.


>All operating systems _where this is possible in the first place_. It is
>not always possible; for example, under very early versions of MS-DOS,
>there was no such thing as a directory.


If you're going to be pedantic, it's equally true to say that such
systems have one directory. And the operating system certainly provides
a way to find out which of the one directories you're in, using the
following code:

In fact, CP/M (and presumably early MS-DOS, though I never used it)
had one directory per disk, and there was no doubt a way to find out
what the current disk was, which would be necessary to get the
equivalent of an "absolute path name".

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
 
Reply With Quote
 
llothar
Guest
Posts: n/a
 
      05-11-2007
On 11 Mai, 14:22, (E-Mail Removed) (Richard Bos) wrote:

> have them, but I would not be surprised at all to learn of embedded ones
> that have files, but no directories, and therefore no path names,
> absolute or relative.


The Oberon system had no paths.

There was only a large BTree and file names looked like
"myapp.mydocs.letter-written-on-11-may.txt" and there was an API to
retrieve all file names at and after a given prefix. So it worked very
much like a hierachical system.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to get Full Path of current directory ? (ASP.net) PHaroZ ASP .Net 5 08-17-2012 08:39 AM
The name <name> does not exist in the current context Montand ASP .Net 1 02-20-2008 08:09 AM
Get Current Full App Path? xeroxero ASP .Net 1 12-08-2006 05:56 AM
best way to discover this process's current memory usage, cross-platform? Alex Martelli Python 25 12-01-2005 11:58 PM



Advertisments