Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Application path  (Read 2231 times)

0 Members and 1 Guest are viewing this topic.

Vit

  • Newbie
  • *
  • Posts: 14
    • View Profile
Application path
« on: September 23, 2011, 10:09:42 am »
What's the easiest way to get the application path? I'm storing my resources in subdirectories next to the executable, and have set up my IDE to set the working directory appropriately. However, when I run it normally, the working directory defaults to the root directory, which doesn't help.
I've had a look online, and it seems that the usual method to get the application path varies by platform; I guess I could use that, but it would be nice if SFML provided an easier way.
I'm using Mac OS X 10.6 and compiling with GCC, but I'd like to be able to get it to work on Windows and Linux too.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Application path
« Reply #1 on: September 23, 2011, 10:22:45 am »
You can get the executable path from the first command line argument (argv[0]). This is not standard, but I think it works on all OSes.
Laurent Gomila - SFML developer

Vit

  • Newbie
  • *
  • Posts: 14
    • View Profile
Application path
« Reply #2 on: September 23, 2011, 10:32:18 am »
Thanks, it seems to work. Can I count on it to work on different platforms (it being non-standard)?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Application path
« Reply #3 on: September 23, 2011, 10:39:38 am »
Like I said it's not standard, and you can find situations where it fails (exec* functions on Unix can pass whatever they want as argv[0]), but it should be ok on Windows/Linux/OS X if you run the executable "normally".
Laurent Gomila - SFML developer

Vit

  • Newbie
  • *
  • Posts: 14
    • View Profile
Application path
« Reply #4 on: September 23, 2011, 10:44:00 am »
That's good to hear. I noticed it stores the path to the executable, not the directory (at least on OS X), so I trim it up to the last forward or back slash. That should work whether it's given an executable path and directory path (as long as the directory path has the slash on the end).

 

anything