How to avoid removing a directory on remove_all using Boost libraries?

I use the boost :: filesystem :: remove_all operation to remove the contents of a directory.

It correctly deletes the contents, but, like a state using the Boost Fileystem Documentation, it also deletes the directory itself.

Is there an easy way to stay with a directory even though it is empty?

+7
source share
1 answer

I think the best way is to iterate over inside the folder and execute remove_all for each item. Code example:

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()); } 
+16
source

All Articles