Link to home
Start Free TrialLog in
Avatar of Member_2_2394978
Member_2_2394978Flag for United Kingdom of Great Britain and Northern Ireland

asked on

File Access via exe Location

Hi,

I'm making a simple tile based game so have many different images as the tiles, at the moment i am simply adding them all by typing in the full path location of each image into my code but want to make an editor which will save the location into a string. Ā But because if i save the full path, once the game is run on another machine the full path's will be different, so had the idea of saving the locations of the images in relation to the location of the executable.

For example if my structure was as follows
/game
/game/images
/game/executables

Is it possible to save the location of the images as game/images so it doesn't matter where the game folder is on the hardrive it will allways go up one level then into the images folder to loacte my tile images?!

Thanks for Help
Avatar of Pierre Cornelius
Pierre Cornelius
Flag of South Africa image

use ExtractFilePath and PAramStr functions. like this:

ExePath:= ExtractFilePath(ParamStr(0));
ImagePath:= GamePath + 'images\';

regards
Pierre
Avatar of Member_2_2394978

ASKER

Hi thanks for quick reponse.

I get the exePath bit but what is 'GamePath' is that a variable!? Thats the furthest up directory isn't it, but where is it coming from?

Cheers
James
Avatar of RickJ
RickJ

Use the following as an example
var ThisDir : String ;

ThisDir := ExtractFilePath(Application.Exename) + 'games/images'
Oops sorry PierreC,
I did not see your post.
I was too slow....

PierreC gets the points.
ASKER CERTIFIED SOLUTION
Avatar of Pierre Cornelius
Pierre Cornelius
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for quick help
James
Sorry, GamePath Should have been ExePath.

My first example will be fine with the following dir structure

c:\game {exe goes here}
c:\game\images

if you prefer the following dir structure, rather use relative path in loadfromfile:
c:\game
c:\game\exe
c:\game\images