Open a folder / change directory

My program creates something that looks like this in the directory it is being run from:

/current_directory
+ file 1 -> Contains list of folder names
+ folder m
+ folder m+1
+ ...
+ folder n-1
+ folder n


1) How do I go into a folder from my program so that it is the new directory I am in?
2) If a folder or file has a space in its name, will I have to use a special character?

Thanks
Last edited on
Please help!
1) You could probably use some non-standard function to change the current working directory of your program. Or you could just specify the directory names in all paths. "dirname/anotherdirname/filename"

2) Probably not, but it could depend on where you use the name.
Last edited on
Most implementations support the (non-standard) chdir() function.

You can also put Boost filesystem to use:
http://www.boost.org/doc/libs/1_50_0/libs/filesystem/doc/index.htm

(Use current_path() to get and set the current directory:
http://www.boost.org/doc/libs/1_50_0/libs/filesystem/doc/reference.html#current_path )
So there is no common c++ method to change directory?
Last edited on
No. That's because there isn't a standard C method either.

Many Unix system calls follow C and thus C++ around. chdir() is one of them, and you will almost certainly find a variant. For example, early Microsoft compilers had chdir(), they've since changed it to _chdir() to remind you it's non-standard.

If you are already using Boost, you should use the Boost functions described above. But if you aren't, just use chdir().
Thanks everyone.
Topic archived. No new replies allowed.