I have a list of files I need to open in a certain function via a LPCSTR argument, but unfortunately they’re located in certain folders (subdirectories of the main program root) with a very long path, and I don’t want to type it in every time I want to pass the filenames.
To be more precise, I have the function D3DXCreateTextureFromFile() which asks for the filename, and for example, I have the files a.png, b.png, c.png located in the “…\Materials\Textures\Textures_For_This\Textures_For_That\More_Specific_Texture_Location\” subdirectory of the main program. How can I register this path and add it to the filename argument in a lean and mean way?
Like some sort of this:
D3DXCreateTextureFromFile(bla, **DECLARED_DIR** + a.png, bla)
//same for b.png, c.png
Or even a subfunction that unifies the path and the filename:
D3DXCreateTextureFromFile(bla, UnifyText(DECLARED_DIR, a.png), bla)
Yep, easiest to make a function to combine the directory with the filename and include separator if required. Because you want to pass this as an argument, you want to avoid allocating a string and having to clean it up… So use the C++
stringclass.I generally do something like this:
Of course, you’ll be relying on that string being implicitly cast to LPCSTR later. If you want to be more explicit then do the (slightly ugly) call to
string::c_str():[Edit]
Another way, if you are doing this single-threaded, is to use a static buffer: