Solved

File Access via exe Location

Posted on 2006-06-26
7
229 Views
Last Modified: 2010-04-05
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
Comment
Question by:James_h1023
  • 3
  • 2
  • 2
7 Comments
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 16983104
use ExtractFilePath and PAramStr functions. like this:

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

regards
Pierre
0
 
LVL 4

Author Comment

by:James_h1023
ID: 16983130
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
 
LVL 8

Expert Comment

by:RickJ
ID: 16983136
Use the following as an example
var ThisDir : String ;

ThisDir := ExtractFilePath(Application.Exename) + 'games/images'
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 8

Expert Comment

by:RickJ
ID: 16983154
Oops sorry PierreC,
I did not see your post.
I was too slow....

PierreC gets the points.
0
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 125 total points
ID: 16983155
Alternatively, in the LoadFromFile method call use relative path

e.g. Image1.Picture.LoadFromFile('..\Images\SomePic.bmp');
0
 
LVL 4

Author Comment

by:James_h1023
ID: 16983170
Thanks for quick help
James
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 16983174
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question