I want to remove folder with subfolders and files in C++17. I'm using experimental/filesystem
namespace filesys = std::experimental::filesystem;
...
uintmax_t n = filesys::remove_all("tmp");
cout << "Deleted " << n << " files or directories\n";
but when i run this code, program throw exception
terminate called after throwing an instance of 'std::experimental::filesystem::v1::__cxx11::filesystem_error'
what(): filesystem error: cannot remove all: Directory not empty [tmp]
Aborted
Using compier g++ 5.4.0
Documentation says:
Deletes the contents of p (if it is a directory) and the contents of all its subdirectories, recursively, then deletes p itself as if by repeatedly applying the POSIX remove. Symlinks are not followed (symlink is removed, not its target)
Is there any problem with my code?
The case of this error being thrown, is likely an issue in the implementation for gcc 5.4: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71313
Using a more recent version of gcc will not throw such an error. For instance, this is not thrown for an empty remove_all
call on gcc 7.4.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With