std::experimental::filesystem:: hard_link_count
From cppreference.net
<
cpp
|
experimental
|
fs
|
定义于头文件
<experimental/filesystem>
|
||
|
std::
uintmax_t
hard_link_count
(
const
path
&
p
)
;
std:: uintmax_t hard_link_count ( const path & p, error_code & ec ) ; |
(1) | (filesystem TS) |
返回由路径 p 标识的文件系统对象的硬链接数量。
非抛出重载在出错时返回 static_cast < uintmax_t > ( - 1 ) 。
目录 |
参数
| p | - | 要检查的路径 |
| ec | - | 非抛出重载中用于错误报告的输出参数 |
返回值
p 的硬链接数量。
异常
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 <iostream> namespace fs = std::experimental::filesystem; int main() { // 在POSIX风格的文件系统中,每个目录至少包含2个硬链接: // 目录自身和特殊成员路径名 "." fs::path p = fs::current_path(); std::cout << "当前路径的硬链接数量为 " << fs::hard_link_count(p) << '\n'; // 每个 ".." 都是指向父目录的硬链接,因此 // 任意目录的硬链接总数等于 2 加上直接子目录的数量 p = fs::current_path() / ".."; // 每个点-点都是指向父目录的硬链接 std::cout << ".. 的硬链接数量为 " << fs::hard_link_count(p) << '\n'; }
输出:
Number of hard links for current path is 2 Number of hard links for .. is 3
参见
|
创建硬链接
(函数) |