to make new folder using mkdir

Hi Guys!,

How can I create new folder using 'mkdir' command?.

How can I specifically give a name to the folder at run time?

Thanks!
Make sure you have a valid path to your new directory in a string. For example, if I wish to add a directory under the CWD:

1
2
3
4
5
6
const char* cwd = getcwd( NULL, 0 );
string path( cwd );
free( cwd );
path += "/";
path += mysubdirectoryname;
mkdir( path.c_str(), 0777 );

(Or with whatever 'mode' is correct.)


That said, you should check out Boost.Filesystem:

 
#include <boost/filesystem.hpp> 
1
2
namespace fs = boost::filesystem;
fs::create_directory( fs::current_path() += mysubdirectoryname );

Hope this helps.
> How can I specifically give a name to the folder at run time?


1
2
3
4
5
6
7
8
9
10
11
#include <fstream>
#include <iostream>

using namespace std;

int main (int argc, char *argv[])
{
cout << "Command line input = " << argv[1] << endl;

return 0;
}
Last edited on
Topic archived. No new replies allowed.