文章目录
- 1. std::experimental::filesystem::exists() 查找文件是否存在
- 2. std::experimental::filesystem::is_directory() 判断是否是一个目录
- 3. std::experimental::filesystem::create_directory() 单层级目录创建
- std::experimental::filesystem::create_directories 多层级目录创建
- 4. class std::experimental::filesystem::directory_iterator 文件迭代器类
- 5. class std::experimental::filesystem::path 文件路径类
🔗cpp官网链接指路
header:
<experimental/filesystem>
编译需链接如下库:
-lstdc++fs
1. std::experimental::filesystem::exists() 查找文件是否存在
content:
bool exists( file_status s ) // 1
bool exists( const path& p ); // 2
bool exists( const path& p, error_code& ec )
1)相当于 status_known(s) && s.type() != file_type::not_found
2)相当于 exists(status(p))
or exists(status(p, ec))
2. std::experimental::filesystem::is_directory() 判断是否是一个目录
bool is_directory( file_status s ); // 1
bool is_directory( const path& p ); // 2
bool is_directory( const path& p, error_code& ec ); // 3
1)相当于 s.type() == file_type::directory
2)相当于 is_directory(status(p))
3)相当于 is_directory(status(p, ec)). Returns false if error occurs.
3. std::experimental::filesystem::create_directory() 单层级目录创建
content:
// 1
bool create_directory( const path& p );
bool create_directory( const path& p, error_code& ec );
// 2
bool create_directory( const path& p, const path& existing_p );
bool create_directory( const path& p, const path& existing_p, error_code& ec );
1) 使用 static_cast(fs::perms::all) 的第二个参数创建目录 p (父目录必须已经存在)。如果 p 已经存在并且已经是一个目录,则函数不执行任何操作(此条件不作为错误处理)。
2)与(1)相同,只不过新目录的属性是从现有的 _ p 复制的(它必须是一个已存在的目录)。复制哪些属性取决于操作系统。
std::experimental::filesystem::create_directories 多层级目录创建
content:
bool create_directories( const path& p );
bool create_directories( const path& p, error_code& ec );
3)对不存在的 p 的每个元素执行 (1)
4. class std::experimental::filesystem::directory_iterator 文件迭代器类
constructor:
directory_iterator();
explicit directory_iterator( const path& p );
directory_iterator( const path& p, error_code& ec );
directory_iterator( const directory_iterator& ) = default;
directory_iterator( directory_iterator&& ) = default;
5. class std::experimental::filesystem::path 文件路径类
constructor:
path();
path( const path& p );
path( path&& p );
template< class Source >
path( const Source& source );
template< class InputIt >
path( InputIt first, InputIt last );
template< class Source >
path( const Source& source, const std::locale& loc );
template< class InputIt >
path( InputIt first, InputIt last, const std::locale& loc );
Decomposition
API | DISCUSSION |
---|---|
root_name | returns the root-name of the path, if present (public member function) |
root_directory | returns the root directory of the path, if present (public member function) |
root_path | returns the root path of the path, if present (public member function) |
relative_path | returns path relative to the root path (public member function) |
parent_path | returns the path of the parent path (public member function) |
filename | returns the filename path component (public member function) |
stem | returns the stem path component (public member function) |
extension | returns the file extension path component (public member function) |
🥰如果本文对你有些帮助,请给个赞或收藏,你的支持是对作者大大莫大的鼓励!!(✿◡‿◡) 欢迎评论留言~~