How do you guys typically delete files on Linux OS? I am thinking of using the unlink
function call, but I wonder if you have a better idea, as the C++ standard has no mention of file deletion operation and it is system dependent.
views:
1685answers:
4
+7
A:
Yep -- the C++ standard leaves this stuff up to the OS, so if you're on Linux (or any POSIX system), unlink()
is what you've got.
The C standard provides remove()
, which you could try, but keep in mind that its behavior is unspecified for anything other than a 'regular file', so it doesn't really shield you from getting into platform-specific filesystem details (links, etc).
If you want something higher-level, more robust, and more portable, check out Boost Filesystem.
tgamblin
2009-03-24 17:07:16
I use remove() in all my code - portability matters to some of us.
anon
2009-03-24 17:19:38
+5
A:
The Standard includes a function called remove which does that. Though i would prefer boost.filesystem
for that (if i already use boost anyway).
#include <cstdio>
int main() {
std::remove("/home/js/file.txt");
}
Johannes Schaub - litb
2009-03-24 17:10:46