Rights Programmes.

I need help, when I start the application I got the following code:

ofstream LAST1("D:\\End.ini");
LAST1 << "1" << endl;
LAST1 << Directory;
LAST1.close();
system("start Second.exe");
exit(1);


In Second.exe application have following code:
char Type;
string Directory;
ifstream Read ("D:\\End.ini");
Read >> Type;
Read >> Directory;
Read.close();

string B = "erase /Q " + Directory;
const char *D = B.c_str();
system(D);

It is only part of the codes

In first application can be erased file End.ini but in second application it does not. The application displays an Access denied. I use Win32. I do not know what I do. :)
Last edited on
What function exactly returns the access denied error? And what value did you specify for Directory in your first application?
Writes me "Error deleting file: Permission denied" and directory can be determined by users and writes to me in any location Then it writes to a file and second program work with it.
Does your first program or your second program return the permission denied error? That's quite a crucial detail.
In second program.
I suspect your access denied error is generated by the system call. You could try forcing a delete by using "erase /F /Q " to force a delete. I wouldn't use this program setup however, it's an enormous security bug to let users erase a directory by force.
I found that in command "remove(umiestnenie.c_str());" lists the error that the program uses a another process
There's probably a program active in the directory you are trying to delete. If a program has its working directory in the directory you are to delete, the delete command will fail with an access denied error. Make sure there are no programs running in this directory before you call delete. Of course I can't know for certain, since I do not know what directory you specified.
And I found that when the program starts again without first program, everything is fine. I think it'll be in the first program.
Is your first program in the directory you are trying to delete? If so, then of course it doesn't work when the first is still active, it has its working directory there.
No, both programs elsewhere than the file I want to delete.
In the code of your first application, what is the value of Directory? Especially here:

 
LAST1 << Directory;
Location determines person but never does not work. When I enter any location always show me access denied.
I believe you are using the wrong command to delete the folder. Windows will only delete empty folders using this command. You can use the RD command (Remove Directory) to delete a directory and all its subfiles. An example:

 
string B = "RD /S /Q " + Directory;


The /S switch means recursive, it will delete all files in the folder as well as the folder itself.
The /Q switch means quiet, it will not ask the user for confirmation.

This should solve your problem, I tested it on my own PC (Windows 10, 64-bit) and the program deleted the given folder just fine.
Only one file I would like to erase. If it was not work, I will be remake my programs. So for now thank you.
For single files you can use the "DEL" command. I thought by the variable name (Directory) that you intended to erase an entire directory, in that case "RD" would solve the problem.
Topic archived. No new replies allowed.