cant copy file i get error 5 access denied i disabled uac and my account has admin rights and its not helping me. i checked the directories and they exist .
Just because you're admin, doesn't mean you have automatic access to everything. If you're excluded using the ACL, you may need to take ownership or use your backup privilege.
what is acl?
i have console application , how i manage to use copyfile. are there other functions to copy file without the need of the user to manually take ownership and things like that?
Just in case this gets edited out, the OP's post was this:
Leonardo321 wrote:
cant copy file i get error 5 access denied i disabled uac and my account has admin rights and its not helping me. i checked the directories and they exist .
If the file is opened and is being used by another program or OS, there's no point in trying. Windows will refuse to give you access regardless.
Can you describe the method you're using to copy the file?
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdint>
int main()
{
std::string filename[2]; // Requested file name
std::ifstream in; // The file i/o stream
std::ofstream out; // The file i/o stream
std::streampos size; // The file size
std::vector<uint8_t> buffer; // Buffer to hold file contents
// Retrieve the file
std::cout << "Enter the name of the file you'd like to load: ";
std::getline(std::cin, filename[0]);
std::cout << "\n";
std::cout << "Where do you want the copy to end up?: ";
std::getline(std::cin, filename[1]);
std::cout << "\n";
// Attempt to open the file
in.open(filename[0]);
// If we can't open the file...
if(!in) {std::cout << "Cannot open file.\n"; std::cin.get(); return 1;}
std::cout << "Getting file parameters...\n";
// Obtain file size
in.seekg(0, std::ios::end);
size = in.tellg();
std::cout << "File size: " << size << ".\n";
std::cout << "Copying file contents into memory...\n";
// Go to the beginning of the file
in.seekg(0, std::ios::beg);
// Allocate memory for the buffer
buffer = std::vector<uint8_t>(size);
// Read in the file
in.read((char*)&buffer[0], size);
std::cout << "File copied into memory.\n";
// Close the file
in.close();
std::cout << "Copying file to hard drive...\n";
// Create a file at the destination
out.open(filename[1]);
if(!out) {std::cout << "Cannot open file.\n"; std::cin.get(); return 1;}
// Write the file contents to the new file
out.write((char*)&buffer[0], size);
std::cout << "File copied.\n";
std::cin.get();
return 0;
}
Output:
Enter the name of the file you'd like to load: hi.txt
Where do you want the copy to end up?: hicpy.txt
Getting file parameters...
File size: 12.
Copying file contents into memory...
File copied into memory.
Copying file to hard drive...
File copied.
Also, be careful that the file size isn't too big (should be smaller than the amount of memory installed in the computer), or Windows will deny memory to the application, and the program will crash.
i tried but when i open the jpg image that was made it says that it is corrupted! why i cant use copy file how to solve error 5 access denied? is there other faster way to accomplish this without write file to memory as described above? I prefer copyfile function instead of alternative ways.
Help!
Leonardo
how can i get those persmissions? how to do it manually i prefer doing it using c++. note: i already and administrator account. the destination directory have read only rights. but i can delete this attribute.
Help me
Leonardo