• Advertisement
Sign in to follow this  

Changing to Subfolders

This topic is 4427 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

Well, this ought to be easy, I'm just not getting it right.. :S I'm trying to change the current dir a subfolder from my actual folder. So, technically, I have this:
char *path = "/Folder/";        //Changing to C:/Folder/
chdir (path); 
and after finding a folder:
chdir (path + c_file.name);
I've tried it with strings and .c_str(), chars, char pointers, and I can never concatenate the two values, because I always get compiler errors.. What am I doing wrong? (For those who keep helping me on other threads, thank you very much, and yes, this is still on the mp3 project :P eheh I will eventually get it right, and this is a fine way to keep learning new things, some by experience, others from helping, but I'll give a credit to all the gamedev users when I get it done =))

Share this post


Link to post
Share on other sites
Advertisement
char *path = "/Folder/"; //Changing to C:/Folder/

chdir (path);

Are you using C or C++? If you are using C++, why don't you use strings and convert them to char* when necessary

string path = "/Folder/";
chdir (path.c_str());

chdir (string(path + c_file.name).c_str()); // This might need adjusting, not sure.

Share this post


Link to post
Share on other sites
Quote:
Original post by Arlanthir
Well, this ought to be easy, I'm just not getting it right.. :S

I'm trying to change the current dir a subfolder from my actual folder. So, technically, I have this:


char *path = "/Folder/"; //Changing to C:/Folder/
chdir (path);


and after finding a folder:


chdir (path + c_file.name);


I've tried it with strings and .c_str(), chars, char pointers, and I can never concatenate the two values, because I always get compiler errors.. What am I doing wrong?

(For those who keep helping me on other threads, thank you very much, and yes, this is still on the mp3 project :P eheh I will eventually get it right, and this is a fine way to keep learning new things, some by experience, others from helping, but I'll give a credit to all the gamedev users when I get it done =))


You can use the strcat function to concatenate strings. There are no operator+() voverloads to perform c-style strings concatenation.

string path = "/Folder/";
chdir (path);
string filename = "foo.bar";
chdir (path + filename);

should work too.

Share this post


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

  • Advertisement