Boost logo

Boost Users :

Subject: Re: [Boost-users] Using filesystem::remove with wildcards
From: Norbert Wenzel (norbert.wenzel.lists_at_[hidden])
Date: 2012-01-20 04:40:31

On 01/20/2012 05:13 AM, toran wrote:
> I am having trouble deleting files with boost::filesystem. Following code does
> not work for me (and I can't find the doc that explains how to do it).
> boost::filesystem::path pt("somepath");
> pt /= ("*.data");
> boost::filesystem::remove(pt);
> pt variable points to the valid set of files, but removal does not happened.
> I will appreciate an advise and may be pointing me to the right place in the
> docs. Thanks.

As far as I know there is no such thing as wildcard replacement in
filesystem. So unless your file is not actually named "*.data" it won't
be found.

If you're trying to delete every .data file in a directory, you'd need
to use the (recursive_)directory_iterator and the .extension() member
function of the path object. And be aware that the iterator is
invalidated when you remove a file.

See this similar question at Stackoverflow:

And be aware that filesystem::remove() returns a bool indicating if the
file existed, so it'd be easy to check in your code. See


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at