Jump to content
  • Advertisement
Sign in to follow this  
wforl

file directory

This topic is 3733 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a Mesh Loading function, which sets up a mesh from an xFile. And i have my xfiles exported from my modelling app, with just the name and extension, not the full directory. ie Image.tga not c:\images\image.tga as i find it easier to work with the code. And have currently been using my calling function as LoadXFile(meshPointer, "files\\xfiles\\Mesh.x", "files\\xfiles\\"); So that the function can load the Mesh from the "files\\xfiles\\Mesh.x" directory, and then create a string using the "files\\xfiles\\" directory , and then append the texture file name extracted from the xfile. such as std::string ImageDirec = "files\\xfiles\\"; ImageDirec.append(imageFile); //imagefile equals image.tga etc now i would like to neaten this up if possible, and rather than have LoadXFile(meshPointer, "files\\xfiles\\Mesh.x", "files\\xfiles\\"); just have LoadXFile(meshPointer, "files\\xfiles\\Mesh.x"); but i, wondering if there is a way to get just the "files\\xfiles\\" from "files\\xfiles\\Mesh.x" obviously the xfiles are going to have different names, so i cant just count back a number of characters.

Share this post


Link to post
Share on other sites
Advertisement

std::string getContainingDir( const std::string& file )
{
// find the last path separator

const size_t lastSep = file.rfind( "\\" );

assert( lastSep != std::string::npos );

return file.substr( 0, lastSep );
}





This is just a very basic example. Obviously you may have to do some more error checking there.


EDIT: Yeah, I guess if you can, just go with boost instead.

Share this post


Link to post
Share on other sites
You can use std::string::rfind() to find the last backslash in a string:

bool LoadXFile(LPD3DXMESH* ppMesh, const std::string& strMeshFileName)
{
std::string strPath;
size_t nPos = strMeshFileName.rfind('\\');
if(nPos != std::string::npos)
strPath = strMeshFileName.substr(0, nPos);
else
strPath = "";

strPath += "SomeTexture.bmp";

// Etc
}




EDIT: Too slow

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!