std::experimental::filesystem::remove, std::experimental::filesystem::remove_all

Header: <experimental/filesystem>

  1. The file or empty directory identified by the path p is deleted as if by the POSIX remove. Symlinks are not followed (symlink is removed, not its target).

# Declarations

bool remove( const path& p );
bool remove( const path& p, error_code& ec );

(filesystem TS)

std::uintmax_t remove_all( const path& p );
std::uintmax_t remove_all( const path& p, error_code& ec );

(filesystem TS)

# Parameters

# Notes

On POSIX systems, this function typically calls unlink and rmdir as needed, on Windows RemoveDirectoryW and DeleteFileW.

# Example

#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";
}

# See also