Verzeichnis rekursiv mit C++17-filesystem-Bibliothek löschen
English
Deutsch
To remove a file or directory (for example my-directory) use remove_all from the C++17 filesystem library:
remove_all-example.cpp
remove_all("my-directory");Dies wird my-directory und alle seine Unterverzeichnisse und Dateien rekursiv entfernen.
Vollständiges Beispiel:
delete-cpp17.cpp
#include <experimental/filesystem>
using namespace std::experimental::filesystem;
int main() {
remove_all("my-directory");
}Falls du GCC verwendest, musst du die Datei so kompilieren:
build-delete-cpp17.sh
g++ -o delete-cpp17 delete-cpp17.cpp -lstdc++fsDu musst die stdc++fs-Bibliothek linken, damit die Funktionen aus der C++17-filesystem-Bibliothek deinem Programm zur Verfügung stehen.
If you just want to remove a file and don’t want to risk deleting an entire directory tree, use remove instead of remove_all or see our previous post How to delete file using C++17 filesystem library
Check out similar posts by category:
C/C++
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow