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

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();

    // ...
}

Thanks really appreciate it :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.