Reputation: 461
I want to check if a .ini file is readonly or not in c++ for windows systems
for example:
if(file == readonly){
//Do this
}
so far i have tried with this and it worked:
ofstream ofs(filename); //test to see if the file successfully opened for writing or not
but as a result it would delete the .ini file and it leave the file blank
PS: 1.it is not a duplicate 2. I have searched all over internet and i found some examples that could have worked but as a result the did not compiled as they should.
Upvotes: 1
Views: 3580
Reputation: 4263
If you're on Windows you can use:
DWORD attr = GetFileAttributes(filename);
if (attr != INVALID_FILE_ATTRIBUTES) {
bool isReadOnly = attr & FILE_ATTRIBUTE_READONLY;
}
Upvotes: 9