0

I want to call opendir() with the argument of the directory the program is being run from. If possible it will be a platform independent way. I'm confused because the accepted answer to a similar question doesn't look to be platform independent. Other answers say use Boost but a reply to this question states initial_path() is deprecated. If it can't be done in a platform independent the target is Windows.

Community
  • 1
  • 1
Celeritas
  • 14,489
  • 36
  • 113
  • 194
  • Have you tried `opendir(.)` with the literal dot '.' for the current working directory? – MartyE Aug 15 '12 at 21:32
  • You can't have a *totally* platform independent path handling, simply beause not all platforms have paths. :-) – Bo Persson Aug 15 '12 at 21:38
  • The second question you link to has the answer: Get the current directory when your program starts, and remember it for later when you need it. A comment confirms that Boost's `current_path` can help you with the first part of that task. The first question's accepted answer is simply another implementation of `current_path`; the answer just neglects to point out that you should call it early in your program and then refer to the saved result. – Rob Kennedy Aug 15 '12 at 21:40

3 Answers3

1

This is cross platform, and tells you the program's current working directory.

char *getcwd(char *buf, size_t size);

This is a posix function, and should be supported on Linux, OsX and Windows. Read about it here:

http://linux.die.net/man/3/getcwd

Rafael Baptista
  • 11,181
  • 5
  • 39
  • 59
1

initial_path() is deprecated, but it effectively called current_path() at the beginning of the program for you and then returned that result on any subsequent calls. So all you need to do is call current_path() at the beginning of your program and store it somewhere.

Jesse Good
  • 50,901
  • 14
  • 124
  • 166
0

Approximately the same question is here.

You can also get help from here: Makefile Tutorial

You can use these commands as well

initial_path()
current_path()
Community
  • 1
  • 1
Hina Khan
  • 1
  • 2