std::experimental::filesystem:: space
|
定义于头文件
<experimental/filesystem>
|
||
|
space_info space
(
const
path
&
p
)
;
space_info space ( const path & p, error_code & ec ) noexcept ; |
(文件系统 TS) | |
确定路径名
p
所在文件系统的信息,实现方式类似于 POSIX
statvfs
函数。
填充并返回一个类型为
space_info
的对象,该对象根据 POSIX
struct statvfs
的成员按如下方式设置:
- space_info. capacity 设置为 f_blocks * f_frsize 的结果。
- space_info. free 设置为 f_bfree * f_frsize 的结果。
- space_info. available 设置为 f_bavail * f_frsize 的结果。
- 任何无法确定的成员将被设置为 static_cast < std:: uintmax_t > ( - 1 ) 。
非抛出重载在出错时将全部成员设置为 static_cast < std:: uintmax_t > ( - 1 ) 。
目录 |
参数
| p | - | 要检查的路径 |
| ec | - | 非抛出重载中用于错误报告的输出参数 |
返回值
文件系统信息(一个
space_info
对象)。
异常
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注释
space_info. available 可能小于 space_info. free 。
示例
#include <experimental/filesystem> #include <iostream> namespace fs = std::experimental::filesystem; int main() { fs::space_info devi = fs::space("/dev/null"); fs::space_info tmpi = fs::space("/tmp"); std::cout << " Capacity Free Available\n" << "/dev: " << devi.capacity << " " << devi.free << " " << devi.available << '\n' << "/tmp: " << tmpi.capacity << ' ' << tmpi.free << ' ' << tmpi.available << '\n'; }
可能的输出:
Capacity Free Available
/dev: 4175114240 4175110144 4175110144
/tmp: 420651237376 411962273792 390570749952
参见
|
文件系统可用空间与空闲空间的信息
(类) |