So, I want to be ableto chdir into a directory, if it exists, if not make the directory. If I am already in the directory, I just don’t need to do anything.
Example
if (cur_dir == "dir_name")
// do stuff
else if ("dir_name" not exist?)
mkdir "dir_name"
chdir "dir_name"
else
chdir "dir_name"
I’ve been googling, I’ve come up with this so far:
if (chdir(Config::CONFIG_FOLDER_NAME) == 0)
{
std::cout << "Network Config Directory not found...\n";
std::cout << "Creating folder called " << Config::CONFIG_FOLDER_NAME << "\n";
mkdir(Config::CONFIG_FOLDER_NAME, 0777);
}
I haven’t yet found a way to check to see what the current directory is.. (not the full path, which is what I did find.)
If you have Boost, you can use Boost.Filesystem:
By the way, if you’re just planning to read a config file, you shouldn’t need to change the working directory. Just read directly, using an absolute path. In Boost.Filesystem, you’d do that this way: