dl
dl_file.h 文件参考

文件系统 更多...

#include <string>
#include <vector>
#include <fstream>
#include "base/dl_tree.h"
#include "memory/dl_buffer.h"

浏览该文件的源代码.

struct  dl::File::SearchRule
 过滤规则,不兼容大小写 更多...
 

命名空间

namespace  dl
 
namespace  dl::File
 文件系统
 
namespace  dl::File::Lua
 文件系统lua接口
 

枚举

enum class  dl::File::CopyMode { dl::File::NONE , dl::File::OVERRIDE , dl::File::SKIP }
 

函数

void dl::File::GetPathFileAll (std::string_view path, std::vector< std::string > &ret, std::string_view regex="", bool recursion=true)
 获取文件夹所有文件
 
void dl::File::GetPathFileAll (std::string_view path, std::vector< std::string > &ret, const SearchRule &rule, bool recursion=true)
 获取文件夹所有文件
 
void dl::File::GetPathContent (std::string_view path, std::vector< std::string > &ret, std::string_view regex="", bool folder=true, bool file=true)
 获取文件夹当前内容
 
void dl::File::GetPathContentAll (std::string_view path, NTree< std::string > &ret)
 获取文件夹所有内容
 
FILE * dl::File::GetFile (std::string_view path_name, bool is_binary=true)
 打开一个文件(只读),可能从压缩包内读取
 
std::ifstream dl::File::Get (std::string_view path_name, bool is_binary=true)
 
std::ofstream dl::File::Set (std::string_view path_name, bool is_binary=true, bool is_app=false)
 打开一个文件(只写)
 
bool dl::File::ConvertMb2U8 (std::string_view path_name, std::string_view out)
 将文本文件从mb转到utf-8
 
std::string dl::File::GetString (std::string_view path_name)
 按文本读文件
 
Buffer dl::File::GetBuffer (std::string_view path_name)
 返回文件内存
 
Buffer dl::File::GetBuffer (std::ifstream &ifs)
 返回文件内存
 
bool dl::File::SaveBuffer (BufferView buf, std::string_view path_name)
 将内存保存为文件
 
bool dl::File::SaveString (BufferView buf, std::string_view path_name)
 将字符串保存为文件
 
bool dl::File::SaveString (std::string_view str, std::string_view path_name)
 将字符串保存为文件
 
uint32_t dl::File::GetCrc32 (std::string_view path_name)
 返回文件Blake2b值
 
bool dl::File::IsExist (std::string_view path_name)
 返回文件是否存在
 
bool dl::File::IsEmpty (std::string_view path)
 返回文件夹是否为空
 
bool dl::File::Delete (std::string_view path_name, bool all=false)
 删除文件或路径
 
void dl::File::DeleteContent (std::string_view path_name)
 删除文件夹内容,但不删除文件夹
 
bool dl::File::Rename (std::string_view src, std::string_view tar)
 重命名文件
 
std::string dl::File::Search (std::string_view path, std::string_view file_name)
 从路径搜索文件
 
bool dl::File::Copy (std::string_view source, std::string_view target, CopyMode mode=CopyMode::NONE, bool recursion=false)
 复制文件或文件夹
 
std::string dl::File::GetExtension (std::string_view path_name, bool has_dot=false)
 返回文件后缀
 
std::string dl::File::GetFileName (std::string_view path_name)
 返回文件名 包含后缀
 
std::string dl::File::GetStem (std::string_view path_name)
 返回文件名 不含后缀
 
std::string dl::File::GetFolderName (std::string_view path_name)
 返回路径所在文件夹名
 
std::string dl::File::GetFilePath (std::string_view path_name)
 返回文件所在路径
 
std::string dl::File::GetAbsolute (std::string_view path_name)
 返回绝对路径
 
std::string dl::File::GetRelative (std::string_view path_name, std::string_view path_base)
 返回相对路径
 
std::string dl::File::GetParentPath (std::string_view path_name)
 返回上一级路径
 
bool dl::File::CreateFolder (std::string_view path)
 创建目录
 
time_t dl::File::GetLastWriteTime (std::string_view path_name)
 返回文件最后修改时间
 
bool dl::File::CheckPathFileModified (std::string_view path_name, const SearchRule &rule, std::string_view cache, bool update)
 判断路径内的文件是否有修改(包括增加、删除文件)
 
std::string dl::File::PathCurrent ()
 返回资源路径
 
std::string dl::File::PathTemp ()
 返回临时路径 rw
 
std::string dl::File::PathStorage ()
 返回存储路径 rw
 
std::string dl::File::PathStorageRoot ()
 返回存储路径根位置 rw
 
std::string dl::File::PathPrivate ()
 返回私有路径 rw
 
std::string dl::File::PathPublic ()
 返回公共路径 rw
 
std::vector< std::string > dl::File::PathRegular ()
 返回常用路径
 
void dl::File::InitFileSystem ()
 
std::vector< std::string > dl::File::Lua::lua_GetPathFileAll_3 (std::string_view path, std::string_view regex, bool recursion)
 获取文件夹所有文件
 
std::vector< std::string > dl::File::Lua::lua_GetPathFileAll_2 (std::string_view path, std::string_view regex)
 获取文件夹所有文件
 
std::vector< std::string > dl::File::Lua::lua_GetPathFileAll_1 (std::string_view path)
 获取文件夹所有文件
 

详细描述

文件系统

版本
1.0
作者
lveyou
日期
21-08-09
注解
统一操作系统的文件操作(区分大小写)
原则0:使用/表示路径分隔符
原则1:路径的结尾规定带有/,因为cd到盘根路径必须加/,还因为相对路径不以/开头
原则2:优先使用相对路径,相对路径开头不带有/
原则3:/表示根路径、./表示当前目录、../表示上一目录
a表示当前目录下的文件
a/表示a文件夹 @ntoe a/b表示a文件夹中的b文件 @ntoe a/b/表示a文件夹中的b文件夹
优先使用C++文件流,为了兼容再以C文件操作实现。
由于std::filesystem的字符编码,为了便于使用,所以封装一层
命名规则:path表示路径、path_name表示路径的文件 file表示文件,folder表示文件夹、content表示所有内容

在文件 dl_file.h 中定义.