News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Fairly new to C++ ..... file permissions.

Started by Xogue, October 08, 2009, 07:39:04 PM

Previous topic - Next topic

Xogue

kinda new to C++   and the forums, so if i mess something up, let me and and i will fix it next time.

but here goes the problem:

i wrote a program that will accept a file path, determined by the user, read each line, and make a new folder in another user defined location.
one folder per line from the text file. the program works just fine, as long as both user defined locations are in unprotected folders (i.e... user folders). id like to know if there is a way to give the program read/write permissions so this wont be a problem. even if i have to prompt the user to allow the program to do so.

here is the code:

#include <iostream>
#include <fstream>
#include <direct.h>
#include <string>

using namespace std;

string filename;
string path;
string name;
string startpath;
fstream file;

int main()
{
cout << "Enter the file path of your text file:";
getline (cin, filename);
cout << "Enter the path that you would like the folders to be created:";
getline (cin, startpath);
ifstream file (filename.c_str());
do {
getline (file, name);
path=startpath + name;
mkdir (path.c_str());}
while (name != "");
cin.ignore();
return 0;
}

MortenMacFly

Quote from: Xogue on October 08, 2009, 07:39:04 PM
kinda new to C++   and the forums, so if i mess something up, let me and and i will fix it next time.
Sorry, wrong forum. Here only discussions related to the Code::Blocks IDE are allowed. Please try a C/C++ programming forum. topic locked.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]