0

I am just 'transfering' from c to C++ and so ... some of the header files #include <direct.h> isn't exactly C++ friendly... I know I can just use them however I want my code to be as C++ly as possible as i'm just learning it...
So.... How do I:

  • mkdir () // make a new folder
  • cddir // change a folder
  • del a empty folder // I know i have to recursively delete all the files etc.
  • go up one folder

I've searched, looked in the boost examples but I haven't found anything...
Would be nice if you could point me in the direction of a tutorial tho.
Thanks in advance....

2
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by ShortYute
0

These samples are using Boost and totally from memory. Please excuse any lapses in Ed's ability to recall details of a complex library. :D The concepts should be accurate though, and easy to correct from the Boost documentation.

> mkdir () // make a new folder

#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>

using boost::filesystem;

int main()
{
    // Create a new directory in the current one
    create_directory(current_path() / "newdir");

    // ...
}

> cddir // change a folder
Just work with a different path. :)

> del a empty folder

#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>

using boost::filesystem;

int main()
{
    path dir = current_path() / "deldir";

    if (dir.is_empty())
        remove(dir);

    // ...
}

> go up one folder

#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>

using boost::filesystem;

int main()
{
    // Get the parent directory
    path current = current_path().branch_path();

    // ...
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.