# Can I create relative filepaths to images in an XCode SDL project?

Can I create relative filepaths to images in an XCode SDL project?

I have to use absolute filepaths as it is, but it would be much easier if I could make the filepaths relative.

• Relative paths work fine. You're probably having a problem where the working directory is not what you expect. Check Xcode's working directory settings. – congusbongus Mar 25 '14 at 2:17

Changing the working directory worked for me recently:

Go to Product -> Scheme -> Edit Scheme.

Then click Run on the left hand panel and then finally enter the path of the files under Working Directory.

All of your paths are then relative to the path you entered.

you could place your files in a folder called resources or whatever you want it to be at the same directory as the exe. For the file path when using a SDL_LoadBMP() or whatnot will be resources/name_of_image.bmp

• You could improve this post easily with some formatting and maybe a little extra explanation to the resources folder. Is it automatically referenced as a resource directory? Does the OP need to create any ties to it or is it a relative string he uses that goes relative to his exe? Explain a little further. – Tom 'Blue' Piddock Mar 28 '14 at 9:46

XCode usually runs your project from an internal directory used for development. One easy way to get the path to your program is to query NSBundle.

NSString * filename = @"images/my_image.jpg";

NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
NSString * fullPath = [filename stringByAppendingPathComponent:filePath];

// fullPath is now the absolute path to the file.


You didn't specify the language, but if you are using C++, you can still use Objective-C inside a .mm file, in the same project.