Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ experimental/filesystem remove_all

Tags:

c++

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?

like image 418
gomess Avatar asked Apr 29 '17 17:04

gomess


1 Answers

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.

like image 198
Olaf73 Avatar answered Sep 29 '22 23:09

Olaf73