# 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.

## 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 on other sites
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 on other sites
Quote:
 Original post by ArlanthirWell, this ought to be easy, I'm just not getting it right.. :SI'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 on other sites
Works like a charm =)
Thank you very much!