Feb 25, 2016 at 7:30pm UTC
What im trying to do is to create a folder/directory using the user input, the path is writing correctly(I think) but the folder is not been created. Here's the Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
void Create_Directory()
{
string Menu_Options;
string NameOfUser;
string Divider = "\\" ;
string NameOfRute;
string NameOfFolder;
string DefaultAddress = "C:\\Users\\" ;
cout << string(20, '_' ) << endl;
cout << "[ 1 ] Creat New Folder:\n\n[ 2 ] Add Files:\n\n[ 3 ] Login\n\n" ;
getline(cin, Menu_Options);
system("cls" );
if (Menu_Options == "1" )
{
cout << string(20, '_' ) << endl;
cout << "Name of User: [ " ;
getline(cin, NameOfUser);
cout << "Name of Rute: [ " ;
getline(cin, NameOfRute);
cout << " ] \n\n Name of Folder:[ " ;
cin >> NameOfFolder;
cout << " ]" ;
DefaultAddress += NameOfUser;//Builder of The path file line.
DefaultAddress += Divider; //Builder of The path file line.
DefaultAddress += NameOfRute;//Builder of The path file line.
DefaultAddress += Divider;//Builder of The path file line.
DefaultAddress += NameOfFolder; //Builder of The path file line.
CreateDirectory(DefaultAddress.c_str(), NULL);
int main()
{
Create_Directory();
system("Pause" );
}
Last edited on Feb 25, 2016 at 7:34pm UTC
Feb 25, 2016 at 8:40pm UTC
Honestly I don't know how to implement that "GetLastError()" so I cant say sorry ; ;
Feb 25, 2016 at 8:45pm UTC
nvm I don't know why but it work, can some one plz elaborate why it sometimes work and sometimes doesn't.