To work with the file system uses boost::filesystem , including to delete files. But what does not work: delete the file if it has a read-only attribute, so you have to reset it in an OS-specific way (on Windows, this is SetFileAttributes() ). How can this attribute be changed in a cross-platform way?
|
2 answers
You can try using _chmod for Windows and chmod for Unix and compiling separately for Windows and Unix:
#include <sys/stat.h> #include <sys/types.h> #ifdef _WIN32 #include <io.h> #define SKIP_READ_ONLY(...) _chmod(...) #else #define SKIP_READ_ONLY(...) chmod(...) #endif - In MinGW in Windows, chmod () also works. In this case, it is possible without conditional compilation (sys / stat.h is enough). - avp
|
boost :: filesystem does not provide this feature. Excerpt from the FAQ :
It is not clear that the system is in a separate library. ("Historical note: " read-only " turned out to be a" guaranteed presence "operation.)
UPD Found a suitable POCO library, with its help you can do this:
#include <Poco/File.h> using namespace Poco; int main() { File f("foo"); f.setReadOnly(); return 0; } I never used it myself.
- Thanks, @gkuznets. So I ask: is there any other way (maybe even another library) with which you can solve this problem without resorting to explicit API calls? - vladimir_ki
|