std::filesystem:: exists
|
헤더 파일에 정의됨
<filesystem>
|
||
|
bool
exists
(
std::
filesystem
::
file_status
s
)
noexcept
;
|
(1) | (C++17부터) |
|
bool
exists
(
const
std::
filesystem
::
path
&
p
)
;
|
(2) | (C++17부터) |
|
bool
exists
(
const
std::
filesystem
::
path
&
p,
std::
error_code
&
ec
)
noexcept
;
|
(3) | (C++17부터) |
주어진 파일 상태나 경로가 존재하는 파일이나 디렉토리에 해당하는지 확인합니다.
목차 |
매개변수
| s | - | 확인할 파일 상태 |
| p | - | 검사할 경로 |
| ec | - | 비예외 발생 오버로드에서 오류 보고를 위한 출력 매개변수 |
반환값
true 주어진 경로나 파일 상태가 존재하는 파일 또는 디렉토리에 해당하는 경우, false 그렇지 않은 경우.
예외
noexcept
로 표시되지 않은 모든 오버로드는 메모리 할당이 실패할 경우
std::bad_alloc
을(를) throw할 수 있습니다.
객체가 존재하지 않으면 파일 시스템 예외가 발생하지 않습니다(반환값을 사용하세요).
참고 사항
이 함수가 제공하는 정보는 일반적으로 디렉터리 순회의 부산물로도 제공됩니다. 디렉터리 순회 중에는 exists ( * iterator ) 를 호출하는 것이 exists ( iterator - > status ( ) ) 보다 효율성이 낮습니다.
예제
#include <cstdint> #include <filesystem> #include <fstream> #include <iostream> namespace fs = std::filesystem; void demo_exists(const fs::path& p, fs::file_status s = fs::file_status{}) { std::cout << p; if (fs::status_known(s) ? fs::exists(s) : fs::exists(p)) std::cout << " exists\n"; else std::cout << " does not exist\n"; } int main() { const fs::path sandbox{"sandbox"}; fs::create_directory(sandbox); std::ofstream{sandbox/"file"}; // create regular file fs::create_symlink("non-existing", sandbox/"symlink"); demo_exists(sandbox); for (const auto& entry : fs::directory_iterator(sandbox)) demo_exists(entry, entry.status()); // use cached status from directory entry fs::remove_all(sandbox); }
출력:
"sandbox" exists "sandbox/symlink" does not exist "sandbox/file" exists
참고 항목
|
(C++17)
(C++17)
|
파일 속성 결정
심볼릭 링크 대상 확인하며 파일 속성 결정 (함수) |
|
(C++17)
|
파일 유형 및 권한 표현
(클래스) |
|
디렉토리 항목이 존재하는 파일 시스템 객체를 참조하는지 확인
(
std::filesystem::directory_entry
의
public 멤버 함수)
|