so, from C++
- how to create new folder?
- how to create new file in new folder?
- how to write/read file from the folder?
To create a folder do this:
#include <direct.h>
int main()
{
mkdir("c:/myfolder");
}
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
To create new file in folder do this:-
#include <direct.h>
#include <fstream>
using namespace std;
int main()
{
mkdir("c:/myfolder");
ofstream write ("c:/myfolder/myfile.txt");
write << "Sup mo fo";
write.close();
}
And so on.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Since mkdir() is not a standard C/C++ function, it's not surprising it doesn't work. The standard language is designed to be ignorant of the 'outside world' (directories, screen, keyboard) so anything that uses them outside the rudimentary I/O is compiler dependant. You'll have to look through your compiler documentation to see what functions it provides.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
How about working with const char arrays instead?
#include <direct.h>
#include <fstream>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char folder[101];
cout << "Name your folder mo fo:";
cin >> folder;
char path[]="c:/";
strcat(path,folder);
mkdir(path);
cout<<"Folder added to c: drive";
cin.get();
}
or look into using c_str() with std::strings?
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
how to check the folder is exist or not?
Try creating the folder.
a) If you get an error, it exists or can't be created.
b) If not, it didn't exist but does now.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944