Discussion:
using boost::filesystem::delete
Sean Farrow
2009-03-03 17:20:46 UTC
Permalink
Hi:
I have a boost::filesystem::wpath object. I need to firstly check if the
file exists, and secondly delete and check the file has been deleted.
How would I go about this?
I've loked at the reference and carn't seem to make sense, are thee any
examples of both these functions?

Any help apreciated.
Sean.
Everton Patitucci
2009-03-03 17:43:20 UTC
Permalink
Post by Sean Farrow
I have a boost::filesystem::wpath object. I need to firstly check if the
file exists, and secondly delete and check the file has been deleted.
How would I go about this?
I've loked at the reference and carn't seem to make sense, are thee any
examples of both these functions?
Any help apreciated.
Sean.
checking if a file exists...
http://www.boost.org/doc/libs/1_38_0/libs/filesystem/doc/reference.html#Predicate-functions
second method.

removing a file...
http://www.boost.org/doc/libs/1_38_0/libs/filesystem/doc/reference.html#Operations-functions
sixth method.


Patuti
Scott McMurray
2009-03-03 19:05:13 UTC
Permalink
Post by Everton Patitucci
Post by Sean Farrow
I have a boost::filesystem::wpath object. I need to firstly check if the
file exists, and secondly delete and check the file has been deleted.
How would I go about this?
I've loked at the reference and carn't seem to make sense, are thee any
examples of both these functions?
Sean.
removing a file...
http://www.boost.org/doc/libs/1_38_0/libs/filesystem/doc/reference.html#Operations-functions
sixth method.
Remove doesn't consider file not found to be an error, so why check?
Checking -- either before or after -- introduces race conditions. If
remove doesn't throw, then the file was gone at that point.
Confirming that seems like a waste of effort.

Christoph Gysin
2009-03-03 17:48:38 UTC
Permalink
Post by Sean Farrow
I have a boost::filesystem::wpath object. I need to firstly check if the
file exists, and secondly delete and check the file has been deleted.
How would I go about this?
I've loked at the reference and carn't seem to make sense, are thee any
examples of both these functions?
Check the reference again:
http://www.boost.org/doc/libs/1_38_0/libs/filesystem/doc/reference.html#Operations-functions

#include <boost/filesystem.hpp>

int main(int argc, char *argv[])
{
boost::filesystem::wpath file(L"file.txt");

if(boost::filesystem::exists(file))
boost::filesystem::remove(file);
}
--
echo mailto: NOSPAM !#$.'<*>'|sed 's. ..'|tr "<*> !#:2" ***@fr33z3
Loading...