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");
> 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
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 hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net