Namespaces
Variants

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

From cppreference.net
헤더 파일에 정의됨 <experimental/filesystem>
bool remove ( const path & p ) ;
bool remove ( const path & p, error_code & ec ) ;
(1) (filesystem TS)
std:: uintmax_t remove_all ( const path & p ) ;
std:: uintmax_t remove_all ( const path & p, error_code & ec ) ;
(2) (filesystem TS)
1) 경로 p 로 식별된 파일 또는 빈 디렉토리는 POSIX remove 함수에 의해 삭제됩니다. 심볼릭 링크는 따라가지 않습니다(심볼릭 링크 자체가 제거되며 대상은 제거되지 않음).
2) p 의 내용(디렉터리인 경우)과 모든 하위 디렉터리의 내용을 재귀적으로 삭제한 후, POSIX remove 를 반복적으로 적용하는 것처럼 p 자체를 삭제합니다. 심볼릭 링크는 따르지 않습니다(심볼릭 링크의 대상이 아닌 심볼릭 링크 자체가 제거됨).

목차

매개변수

p - 삭제할 경로
ec - 비예외 발생 오버로드에서 오류 보고를 위한 출력 매개변수

반환값

1) true 파일이 삭제된 경우, false 파일이 존재하지 않았던 경우. error_code & 인수를 받는 오버로드는 오류 발생 시 false 를 반환합니다.
2) 존재하지 않던 파일과 디렉토리의 수(처음부터 p 가 존재하지 않았던 경우 0일 수 있음)를 반환합니다. error_code & 인수를 받는 오버로드는 오류 시 static_cast < std:: uintmax_t > ( - 1 ) 를 반환합니다.

예외

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 명세:
noexcept

참고 사항

POSIX 시스템에서 이 함수는 일반적으로 필요한 경우 unlink rmdir 를 호출하며, Windows에서는 RemoveDirectoryW DeleteFileW 를 호출합니다.

예제

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

가능한 출력:

Deleted 2 files or directories

참고 항목

파일을 삭제함
(함수)