dl
函数
dl::File 命名空间参考

函数

void GetPathFileAll (std::string_view path, std::vector< std::string > &ret, std::string_view regex="", bool recursion=true)
 遍历文件夹所有文件 更多...
 
FILE * GetFile (std::string_view path_name, bool is_binary=true)
 打开一个文件(只读),可能从压缩包内读取 更多...
 
std::ifstream Get (std::string_view path_name, bool is_binary=true)
 
bool ConvertMb2U8 (std::string_view path_name, std::string_view out)
 将文本文件从mb转到utf-8 更多...
 
Buffer GetBuffer (std::string_view path_name)
 返回文件内存 更多...
 
Buffer GetBuffer (std::ifstream &ifs)
 返回文件内存 更多...
 
bool SaveBuffer (const Buffer &buf, std::string_view path_name)
 将内存保存为文件 更多...
 
uint32_t GetCrc32 (std::string_view path_name)
 ‍** 更多...
 
bool IsExist (std::string_view path_name)
 返回文件是否存在 更多...
 
bool Delete (std::string_view path_name, bool all=false)
 删除文件或路径 更多...
 
void DeleteContent (std::string_view path_name)
 删除文件夹内容,但不删除文件夹 更多...
 
bool Copy (std::string_view source, std::string_view target)
 复制文件 更多...
 
std::string GetExtension (std::string_view path_name, bool has_dot=false)
 返回文件后缀 更多...
 
std::string GetFilename (std::string_view path_name)
 返回文件名 更多...
 
std::string GetStem (std::string_view path_name)
 返回文件名不含后缀 更多...
 
bool CreateDirectory (std::string_view path)
 创建目录 更多...
 
time_t GetLastWriteTime (std::string_view path_name)
 返回文件最后修改时间 更多...
 
bool CheckPathFileModified (std::string_view path_name, std::string_view cache, bool update)
 判断路径内的文件是否有修改(包括增加、删除文件) 更多...
 
std::string GetPathCurrent ()
 返回工作目录 更多...
 
std::string GetPathTemp ()
 返回临时目录 更多...
 

函数说明

◆ CheckPathFileModified()

bool dl::File::CheckPathFileModified ( std::string_view  path_name,
std::string_view  cache,
bool  update 
)

判断路径内的文件是否有修改(包括增加、删除文件)

参数
[in]path_name路径名称
[in]cache用于生成和保存的文件信息的文件
[in]updatecache文件如果存在且不匹配,是否更新cache
注解
第一次必然返回真,然后根据文件信息生成cache文件。下次调用会依据cache文件判断路径内文件是否有修改 发生错误返回真
根据文件修改时间判断

◆ ConvertMb2U8()

bool dl::File::ConvertMb2U8 ( std::string_view  path_name,
std::string_view  out 
)

将文本文件从mb转到utf-8

参数
[in]path_name路径名称
[in]out输出文件的路径名称
返回值
如果失败,会输出日志

◆ Copy()

bool dl::File::Copy ( std::string_view  source,
std::string_view  target 
)

复制文件

参数
[in]source源文件
[in]target目标文件
注解
文件夹不存在会失败

◆ CreateDirectory()

bool dl::File::CreateDirectory ( std::string_view  path)

创建目录

参数
[in]path路径

◆ Delete()

bool dl::File::Delete ( std::string_view  path_name,
bool  all = false 
)

删除文件或路径

参数
[in]path_name路径名称
[in]all为真时可以删除非空文件夹
返回值
删除失败返回假

◆ DeleteContent()

void dl::File::DeleteContent ( std::string_view  path_name)

删除文件夹内容,但不删除文件夹

参数
[in]path_name路径名称
注解
文件夹不存在则什么都不做

◆ Get()

std::ifstream dl::File::Get ( std::string_view  path_name,
bool  is_binary = true 
)

◆ GetBuffer() [1/2]

Buffer dl::File::GetBuffer ( std::ifstream &  ifs)

返回文件内存

参数
[in]ifs文件句柄
返回值
需要手动释放内存

◆ GetBuffer() [2/2]

Buffer dl::File::GetBuffer ( std::string_view  path_name)

返回文件内存

参数
[in]path_name路径名称
返回值
需要手动释放内存

◆ GetCrc32()

uint32_t dl::File::GetCrc32 ( std::string_view  path_name)

‍**

‍**

返回文件crc32值

参数
[in]path_name路径名称
返回值
0代表失败

◆ GetExtension()

std::string dl::File::GetExtension ( std::string_view  path_name,
bool  has_dot = false 
)

返回文件后缀

参数
[in]path_name
[in]has_dot是否含有“.”,比如.txt而不是txt

◆ GetFile()

FILE * dl::File::GetFile ( std::string_view  path_name,
bool  is_binary = true 
)

打开一个文件(只读),可能从压缩包内读取

参数
[in]path_name路径名称
[in]binary是否以二进制模式打开
返回值
文件句柄
注解
如果成功读取,则用户需要手动释放文件

◆ GetFilename()

std::string dl::File::GetFilename ( std::string_view  path_name)

返回文件名

参数
[in]path_name

◆ GetLastWriteTime()

time_t dl::File::GetLastWriteTime ( std::string_view  path_name)

返回文件最后修改时间

参数
[in]path_name路径名称
注解
复制相同文件也会更新,建议使用GetCrc32

◆ GetPathCurrent()

std::string dl::File::GetPathCurrent ( )

返回工作目录

◆ GetPathFileAll()

void dl::File::GetPathFileAll ( std::string_view  path,
std::vector< std::string > &  ret,
std::string_view  regex = "",
bool  recursion = true 
)

遍历文件夹所有文件

参数
[in]path路径
[out]ret返回的文件名
[in]regex正则表达式,例如 .(png|jpg)$
[in]recursion递归文件夹

◆ GetPathTemp()

std::string dl::File::GetPathTemp ( )

返回临时目录

注解
这个位置进行文件写入,容易引起误杀,请改用g_factory的接口

◆ GetStem()

std::string dl::File::GetStem ( std::string_view  path_name)

返回文件名不含后缀

参数
[in]path_name

◆ IsExist()

bool dl::File::IsExist ( std::string_view  path_name)

返回文件是否存在

参数
[in]path_name路径名称
注解
不包含压缩包内文件

◆ SaveBuffer()

bool dl::File::SaveBuffer ( const Buffer &  buf,
std::string_view  path_name 
)

将内存保存为文件

参数
[in]buf内存
[in]path_name保存路径(文件夹必须存在)