Hooch
Hooch

Reputation: 29673

Relative path problem - one dir up

This is workig: I have my exe in the same directory as Images folder;

Main:
|-Images
  |-cross_ball
    |-frame.bmp
|-game.exe

I'm refering to frame.bmp in my game.exe.

This path is workig good: "Images\\cross_ball\\frame.bmp"

This is not working: Exe is in bin folder. bin folder is in the same folder as Images folder;

Main:
|-Images
  |-cross_ball
    |-frame.bmp
|-bin
  |-game.exe

This path is not working: "..\\Images\\cross_ball\\frame.bmp"

Upvotes: 0

Views: 2131

Answers (3)

Carey Gregory
Carey Gregory

Reputation: 6846

If "Images\cross_ball\frame.bmp" is working, then your app's current directory isn't the Images directory like you think it is. It must be one dir up for that to work. That would also explain why moving the exe to the bin directory fails.

Are you starting your app from a shortcut or in a debugger? Shortcuts and debuggers specify the app's current directory, which isn't necessarily the same directory the exe is in.

Upvotes: 3

John Humphreys
John Humphreys

Reputation: 39294

It appears that your logic is fine. Are you sure your process hasn't changed the current working directory - i.e. Main/bin/ might not be your working directory when you go to make this change in the executable.

Upvotes: 0

EvilTeach
EvilTeach

Reputation: 28837

As an experiment, replace each \ by \\ and test again.

Back slash is generally used for escape sequences like '\n'.

By putting two of them together, the run time ought to change them into one.

"Images\\cross_ball\\frame.bmp"

Upvotes: 0

Related Questions