std::experimental::filesystem:: file_size
From cppreference.net
<
cpp
|
experimental
|
fs
|
헤더 파일에 정의됨
<experimental/filesystem>
|
||
|
std::
uintmax_t
file_size
(
const
path
&
p
)
;
std:: uintmax_t file_size ( const path & p, error_code & ec ) ; |
(1) | (filesystem TS) |
일반 파일
p
의 크기를 반환하며,
POSIX
stat
으로 얻은 구조체의
st_size
멤버를 읽는 방식으로 결정됩니다(심볼릭 링크는 따라갑니다).
디렉터리(그리고 일반 파일이나 심볼릭 링크가 아닌 다른 파일)의 크기를 확인하려는 시도는 오류로 처리됩니다.
비예외 오버로드는 오류 발생 시 - 1 을 반환합니다.
목차 |
매개변수
| p | - | 검사할 경로 |
| ec | - | 비예외 발생 오버로드에서 오류 보고를 위한 출력 매개변수 |
반환값
파일의 크기(바이트 단위).
예외
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
예제
이 코드 실행
#include <experimental/filesystem> #include <fstream> #include <iostream> namespace fs = std::experimental::filesystem; int main() { fs::path p = fs::current_path() / "example.bin"; std::ofstream(p).put('a'); // 크기가 1인 파일 생성 std::cout << "File size = " << fs::file_size(p) << '\n'; fs::remove(p); try { fs::file_size("/dev"); // 디렉토리 크기 가져오기 시도 } catch (fs::filesystem_error& e) { std::cout << e.what() << '\n'; } }
가능한 출력:
File size = 1 filesystem error: cannot get file size: Is a directory [/dev]
참고 항목
|
일반 파일의 크기를 절단 또는 제로 필로 변경
(함수) |
|
|
파일 시스템에서 사용 가능한 여유 공간 확인
(함수) |