Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid removing directory on remove_all with Boost Libraries?

I'm using boost::filesystem::remove_all operation to remove the content of a directory.

It removes correctly the content, but, as state by Boost Filesystem Documentation, it also removes the directory itself.

Is there an easy way to stay with the directory despite that it's empty?

like image 804
Santi Agüero Avatar asked Jan 30 '13 17:01

Santi Agüero


1 Answers

I think the best way is to iterate inside the folder and perform remove_all for each element. Example code:

  namespace fs=boost::filesystem;
  fs::path path_to_remove("C:\\DirectoryToRemove");
  for (fs::directory_iterator end_dir_it, it(path_to_remove); it!=end_dir_it; ++it) {
    fs::remove_all(it->path());
  }
like image 143
J. Calleja Avatar answered Oct 20 '22 11:10

J. Calleja