std::experi...::remove_all(3)
π
std::experi...::remove_all(3) π
okay so we're in the C++ Standard Libary manual β yes, that's the spelling in the header, and we're respecting it β and this page is literally the delete-y duo: remove and remove_all. no cap, recursive deletion is giving main character energy. π§’β¨
πΈ NAME πΈ
std::experimental::filesystem::remove,std::experimental::filesystem::remove_all β std::experimental::filesystem::remove,std::experimental::filesystem::remove_all π
π¦ Synopsis π¦
Defined in header <experimental/filesystem>:
bool remove( const path& p ); (1)
(filesystem TS)
bool remove( const path& p, error_code& ec );
std::uintmax_t remove_all( const path& p ); (2)
(filesystem TS)
std::uintmax_t remove_all( const path& p, error_code& ec );
- The file or empty directory identified by the path
pis deleted as if by the POSIXremove. Symlinks are not followed (symlink is removed, not its target). π«Ά - Deletes the contents of
p(if it is a directory) and the contents of all its subdirectories, recursively, then deletespitself as if by repeatedly applying the POSIXremove. Symlinks are not followed (symlink is removed, not its target). π
π Parameters π
pβ path to delete.ecβ out-parameter for error reporting in the non-throwing overload.
π Return value π
trueif the file was deleted,falseif it did not exist. The overload that takeserror_code&argument returnsfalseon errors.- Returns the number of files and directories that were deleted (which may be zero if
pdid not exist to begin with). The overload that takeserror_code&argument returnsstatic_cast<std::uintmax_t>(-1)on error.
π Exceptions π
The overload that does not take an error_code& parameter throws filesystem_error on underlying OS API errors, constructed with p as the first argument and the OS error code as the error code argument. std::bad_alloc may be thrown if memory allocation fails.
The overload taking an error_code& parameter sets it to the OS API error code if an OS API call fails, and executes ec.clear() if no errors occur. This overload has noexcept specification: noexcept.
π§ Notes π§
On POSIX systems, this function typically calls unlink and rmdir as needed, on Windows RemoveDirectoryW and DeleteFileW.
π Example π
// Run this code
#include <cstdint>
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
fs::path dir = fs::temp_directory_path();
fs::create_directories(dir / "abcdef/example");
std::uintmax_t n = fs::remove_all(dir / "abcdef");
std::cout << "Deleted " << n << " files or directories\n";
}
Possible output:
Deleted 2 files or directories
π₯ See also π₯
removeβ erases a file (function)
π·οΈ Categories π·οΈ
- Noindexed pages
- unconditionally noexcept
π Hidden categories π
- Pages with unreviewed unconditional noexcept template
- Pages with unreviewed noexcept template
mwah π β this lil page came from http://cppreference.com, dated 2024.06.10, and it's literally the std::experi...::remove_all(3) page. now go be iconic with your filesystem, bestie π
β¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms