cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
file.hpp
Go to the documentation of this file.
1#pragma once
2#include <filesystem>
3#include <functional>
4#include <vector>
5
6#include <cpp-toolbox/cpp-toolbox_export.hpp>
7
9
11{
12
13using file_time_type = std::filesystem::file_time_type;
14using file_type = std::filesystem::file_type;
15
32CPP_TOOLBOX_EXPORT auto string_to_path(const std::string& str)
33 -> std::filesystem::path;
34
57CPP_TOOLBOX_EXPORT auto path_to_string(const std::filesystem::path& path)
58 -> std::string;
59
85CPP_TOOLBOX_EXPORT auto get_file_size(const std::filesystem::path& path)
86 -> std::size_t;
87
105CPP_TOOLBOX_EXPORT auto get_absolute_path(const std::filesystem::path& path)
106 -> std::filesystem::path;
107
130CPP_TOOLBOX_EXPORT auto get_relative_path(const std::filesystem::path& path,
131 const std::filesystem::path& base)
132 -> std::filesystem::path;
133
153CPP_TOOLBOX_EXPORT auto get_parent_path(const std::filesystem::path& path)
154 -> std::filesystem::path;
155
175CPP_TOOLBOX_EXPORT auto get_file_name(const std::filesystem::path& path)
176 -> std::string;
177
198CPP_TOOLBOX_EXPORT auto get_file_extension(const std::filesystem::path& path)
199 -> std::string;
200
217CPP_TOOLBOX_EXPORT auto copy_file(const std::filesystem::path& src,
218 const std::filesystem::path& dst) -> bool;
219
236CPP_TOOLBOX_EXPORT auto move_file(const std::filesystem::path& src,
237 const std::filesystem::path& dst) -> bool;
238
263CPP_TOOLBOX_EXPORT auto delete_file(const std::filesystem::path& path) -> bool;
264
290CPP_TOOLBOX_EXPORT auto file_exists(const std::filesystem::path& path) -> bool;
291
316CPP_TOOLBOX_EXPORT auto create_directory(const std::filesystem::path& path)
317 -> bool;
318
344CPP_TOOLBOX_EXPORT auto directory_exists(const std::filesystem::path& path)
345 -> bool;
346
371CPP_TOOLBOX_EXPORT auto delete_directory(const std::filesystem::path& path)
372 -> bool;
373
394CPP_TOOLBOX_EXPORT auto get_current_directory() -> std::filesystem::path;
395
423CPP_TOOLBOX_EXPORT auto path_type(const std::filesystem::path& path)
424 -> std::filesystem::file_type;
425
449CPP_TOOLBOX_EXPORT auto is_regular_file(const std::filesystem::path& path)
450 -> bool;
451
475CPP_TOOLBOX_EXPORT auto is_directory(const std::filesystem::path& path) -> bool;
476
500CPP_TOOLBOX_EXPORT auto is_symlink(const std::filesystem::path& path) -> bool;
501
522CPP_TOOLBOX_EXPORT auto is_fifo(const std::filesystem::path& path) -> bool;
523
542CPP_TOOLBOX_EXPORT auto is_socket(const std::filesystem::path& path) -> bool;
543
562CPP_TOOLBOX_EXPORT auto is_block_file(const std::filesystem::path& path)
563 -> bool;
564
583CPP_TOOLBOX_EXPORT auto is_character_file(const std::filesystem::path& path)
584 -> bool;
585
606CPP_TOOLBOX_EXPORT auto is_other(const std::filesystem::path& path) -> bool;
607
626CPP_TOOLBOX_EXPORT auto is_empty(const std::filesystem::path& path) -> bool;
627
652CPP_TOOLBOX_EXPORT auto get_creation_time(const std::filesystem::path& path)
654
679CPP_TOOLBOX_EXPORT auto get_last_access_time(const std::filesystem::path& path)
681
706CPP_TOOLBOX_EXPORT auto get_last_write_time(const std::filesystem::path& path)
708
732CPP_TOOLBOX_EXPORT auto get_symlink_target(const std::filesystem::path& path)
733 -> std::filesystem::path;
734
758CPP_TOOLBOX_EXPORT auto traverse_directory(const std::filesystem::path& path)
759 -> std::vector<std::filesystem::path>;
760
784CPP_TOOLBOX_EXPORT auto list_files_in_directory(
785 const std::filesystem::path& path, const std::string& extension = "")
786 -> std::vector<std::filesystem::path>;
787
813CPP_TOOLBOX_EXPORT auto list_files_in_directory(
814 const std::filesystem::path& path,
815 const std::vector<std::string>& extensions)
816 -> std::vector<std::filesystem::path>;
817
846CPP_TOOLBOX_EXPORT auto recursive_traverse_directory(
847 const std::filesystem::path& path) -> std::vector<std::filesystem::path>;
848
875CPP_TOOLBOX_EXPORT auto traverse_directory_files(
876 const std::filesystem::path& path,
877 std::function<void(const std::filesystem::path&)>& callback) -> void;
878
906 const std::filesystem::path& path,
907 std::function<void(const std::filesystem::path&)>& callback) -> void;
908
933CPP_TOOLBOX_EXPORT auto get_current_working_directory()
934 -> std::filesystem::path;
935
936} // namespace toolbox::file
通用的编译器、平台、架构检测和实用宏定义 / Common macros for compiler, platform, architecture detection and utility macro...
Definition file.hpp:11
CPP_TOOLBOX_EXPORT auto get_file_size(const std::filesystem::path &path) -> std::size_t
获取文件的字节大小 / Get the size of a file in bytes
CPP_TOOLBOX_EXPORT auto recursive_traverse_directory(const std::filesystem::path &path) -> std::vector< std::filesystem::path >
递归遍历目录 / Recursively traverse a directory
CPP_TOOLBOX_EXPORT auto get_current_directory() -> std::filesystem::path
获取当前工作目录 / Get the current working directory
CPP_TOOLBOX_EXPORT auto is_fifo(const std::filesystem::path &path) -> bool
检查路径是否为FIFO(命名管道) / Check if a path is a FIFO (named pipe)
CPP_TOOLBOX_EXPORT auto list_files_in_directory(const std::filesystem::path &path, const std::string &extension="") -> std::vector< std::filesystem::path >
列出目录下指定扩展名的所有文件/Lists all files in a directory with the specified extension
CPP_TOOLBOX_EXPORT auto get_last_access_time(const std::filesystem::path &path) -> file_time_type
获取文件的最后访问时间 / Get the last access time of a file
CPP_TOOLBOX_EXPORT auto move_file(const std::filesystem::path &src, const std::filesystem::path &dst) -> bool
移动文件 / Move a file
CPP_TOOLBOX_EXPORT auto directory_exists(const std::filesystem::path &path) -> bool
检查指定路径是否存在目录 / Check if a directory exists at the specified path
CPP_TOOLBOX_EXPORT auto delete_directory(const std::filesystem::path &path) -> bool
删除指定路径的目录 / Delete a directory at the specified path
CPP_TOOLBOX_EXPORT auto is_regular_file(const std::filesystem::path &path) -> bool
检查路径是否为常规文件 / Check if a path is a regular file
CPP_TOOLBOX_EXPORT auto file_exists(const std::filesystem::path &path) -> bool
检查指定路径是否存在文件 / Check if a file exists at the specified path
CPP_TOOLBOX_EXPORT auto is_other(const std::filesystem::path &path) -> bool
检查路径是否为未知类型 / Check if a path is of an unknown type
CPP_TOOLBOX_EXPORT auto get_symlink_target(const std::filesystem::path &path) -> std::filesystem::path
获取符号链接的目标路径 / Get the target of a symbolic link
CPP_TOOLBOX_EXPORT auto string_to_path(const std::string &str) -> std::filesystem::path
将字符串转换为文件系统路径 / Convert a string to a filesystem path
CPP_TOOLBOX_EXPORT auto recursive_traverse_directory_files(const std::filesystem::path &path, std::function< void(const std::filesystem::path &)> &callback) -> void
递归遍历目录并为每个文件调用回调函数 / Recursively traverse a directory and call a callback for each file
CPP_TOOLBOX_EXPORT auto is_block_file(const std::filesystem::path &path) -> bool
检查路径是否为块设备 / Check if a path is a block device
CPP_TOOLBOX_EXPORT auto is_empty(const std::filesystem::path &path) -> bool
检查路径是否为空 / Check if a path is empty
CPP_TOOLBOX_EXPORT auto traverse_directory_files(const std::filesystem::path &path, std::function< void(const std::filesystem::path &)> &callback) -> void
遍历目录并为每个文件调用回调函数 / Traverse a directory and call a callback for each file
CPP_TOOLBOX_EXPORT auto get_absolute_path(const std::filesystem::path &path) -> std::filesystem::path
获取文件或目录的绝对路径 / Get the absolute path of a file or directory
CPP_TOOLBOX_EXPORT auto get_file_name(const std::filesystem::path &path) -> std::string
获取路径的文件名部分 / Get the file name component of a path
CPP_TOOLBOX_EXPORT auto get_last_write_time(const std::filesystem::path &path) -> file_time_type
获取文件的最后修改时间 / Get the last write time of a file
CPP_TOOLBOX_EXPORT auto is_socket(const std::filesystem::path &path) -> bool
检查路径是否为套接字 / Check if a path is a socket
std::filesystem::file_time_type file_time_type
Definition file.hpp:13
CPP_TOOLBOX_EXPORT auto get_relative_path(const std::filesystem::path &path, const std::filesystem::path &base) -> std::filesystem::path
获取两个路径之间的相对路径 / Get the relative path between two paths
CPP_TOOLBOX_EXPORT auto is_directory(const std::filesystem::path &path) -> bool
检查路径是否为目录 / Check if a path is a directory
CPP_TOOLBOX_EXPORT auto traverse_directory(const std::filesystem::path &path) -> std::vector< std::filesystem::path >
遍历目录 / Traverse a directory
CPP_TOOLBOX_EXPORT auto path_to_string(const std::filesystem::path &path) -> std::string
将文件系统路径转换为字符串 / Convert a filesystem path to a string
CPP_TOOLBOX_EXPORT auto copy_file(const std::filesystem::path &src, const std::filesystem::path &dst) -> bool
复制文件 / Copy a file
CPP_TOOLBOX_EXPORT auto is_character_file(const std::filesystem::path &path) -> bool
检查路径是否为字符设备 / Check if a path is a character device
CPP_TOOLBOX_EXPORT auto get_parent_path(const std::filesystem::path &path) -> std::filesystem::path
获取路径的父目录 / Get the parent directory of a path
CPP_TOOLBOX_EXPORT auto get_current_working_directory() -> std::filesystem::path
获取当前工作目录 / Get the current working directory
std::filesystem::file_type file_type
Definition file.hpp:14
CPP_TOOLBOX_EXPORT auto get_file_extension(const std::filesystem::path &path) -> std::string
获取路径的文件扩展名 / Get the file extension of a path
CPP_TOOLBOX_EXPORT auto delete_file(const std::filesystem::path &path) -> bool
删除指定路径的文件 / Delete a file at the specified path
CPP_TOOLBOX_EXPORT auto get_creation_time(const std::filesystem::path &path) -> file_time_type
获取文件的创建时间 / Get the creation time of a file
CPP_TOOLBOX_EXPORT auto create_directory(const std::filesystem::path &path) -> bool
在指定路径创建目录 / Create a directory at the specified path
CPP_TOOLBOX_EXPORT auto path_type(const std::filesystem::path &path) -> std::filesystem::file_type
获取指定路径的文件系统对象类型 / Get the type of the filesystem object at the specified path
CPP_TOOLBOX_EXPORT auto is_symlink(const std::filesystem::path &path) -> bool
检查路径是否为符号链接 / Check if a path is a symbolic link