• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

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
0
James_h1023
Asked:
James_h1023
  • 3
  • 2
  • 2
1 Solution
 
Pierre CorneliusCommented:
use ExtractFilePath and PAramStr functions. like this:

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

regards
Pierre
0
 
James_h1023Author Commented:
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
0
 
RickJCommented:
Use the following as an example
var ThisDir : String ;

ThisDir := ExtractFilePath(Application.Exename) + 'games/images'
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RickJCommented:
Oops sorry PierreC,
I did not see your post.
I was too slow....

PierreC gets the points.
0
 
Pierre CorneliusCommented:
Alternatively, in the LoadFromFile method call use relative path

e.g. Image1.Picture.LoadFromFile('..\Images\SomePic.bmp');
0
 
James_h1023Author Commented:
Thanks for quick help
James
0
 
Pierre CorneliusCommented:
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
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now