It is necessary to delete files, including files "Read Only." If the properties are ticked "Read Only", then remove () cannot be removed. I tried to get information about the file in the _finddata_t structure and change the attrib field in it,

char[50] path; // Путь к файлу и маска поиска _finddata_t file; _findfirst(path, &file); file.attrib = _A_NORMAL;// Попытка сделать файл без запретов на чтение или запись 

but also nothing. The file is still not deleted and the check mark is not removed. Although if you uncheck the box manually (right-click on file-> properties), it is only then deleted.

    2 answers 2

    If it’s about Windows, then you can use the SetFileAttributesW function

      POSIX defines such a function - _chmod , so, as for me, the most portable way to delete an R / O file is approximately

       int killFile(const char * name) { if (name==0) return 1; if (remove(name)) { _chmod(name,_S_IWRITE); } else return 0; return remove(name); }; 

      Those. if the first attempt to delete fails, remove the R / O and try again ...

      PS What you are doing is about the same as, having counted the money in your wallet, write the amount on a piece of paper (remove the file information in the file structure). After that, increase the amount of paper on paper (change the file structure field) 10 times and hope that something will increase in the wallet ...