Shortest
Shortest
#include<string>
#include<fstream>
#include<sys/stat.h>
#include<direct.h>
#include<cstdlib>
if(stat(folderPath.c_str(), &info)!=0){
return false;
}else if(info.st_mode & S_IFDIR){
return true;
}else{
return false;
}
}
void createFolder(){
string foldername, folderPath;
if(folderExists(folderPath)){
cout<<"Folder exists !!";
}else{
if(mkdir(folderPath.c_str())==0){
cout<<"Folder created Successfully"<<endl;
}else{
cerr<<"Error creating folder"<<endl;
}
}
}
void createFile(){
string folderPath, filePath;
if(!folderExists(folderPath)){
cout<<"Do you want to create file? ";
char choice;
cin>>choice;
if(choice=='y' || choice=='Y'){
createFolder();
}else{
cout<<"file aborted!!";
return;
}
}
string filename;
cout<<"Enter Filename: ";
cin>>filename;
ofstream outFile(filePath);
string content;
cout<<"Enter Content (Type END to the new line to stop)"<<endl;
while(true){
getline(cin,content);
if(content=="END")break;
outFile<<content<<endl;
}
outFile.close();
void readFile(){
string folderPath, filename, filePath;
ifstream inFile(filePath);
string line;
cout<<"reading from "<<filename<<endl;
while(getline(inFile, line)){
cout<<line<<endl;
}
}
int main(){
int choice;
do{
cout<<"Main Menu:"<<endl;
cout<<"1. Create folder"<<endl;
cout<<"2. Create File"<<endl;
cout<<"3. Read File"<<endl;
cout<<"4. Exit"<<endl;
cout<<"Choose option: ";
cin>>choice;
cin.ignore();
switch(choice){
case 1:
createFolder();
break;
case 2:
createFile();
break;
case 3:
readFile();
break;
case 4:
break;
default:
cout<<"Invalid Input!!"<<endl;
}