dl
dl::File 命名空间参考

文件系统 更多...

命名空间

namespace  Lua
 文件系统lua接口
 

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

枚举

enum class  CopyMode { NONE , OVERRIDE , SKIP }
 

函数

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

详细描述

文件系统

枚举类型说明

◆ CopyMode

enum class dl::File::CopyMode
strong
枚举值
NONE 

文件已存在,则返回失败

OVERRIDE 

覆盖

SKIP 

跳过

在文件 dl_file.h232 行定义.

函数说明

◆ CheckPathFileModified()

bool dl::File::CheckPathFileModified ( std::string_view path_name,
const SearchRule & rule,
std::string_view cache,
bool update )

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

参数
[in]path_name路径名称
[in]rule匹配规则
[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,
CopyMode mode = CopyMode::NONE,
bool recursion = false )

复制文件或文件夹

参数
[in]source源文件
[in]target目标文件
[in]mode复制模式
[in]recursion递归

◆ CreateFolder()

bool dl::File::CreateFolder ( 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 )

◆ GetAbsolute()

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

返回绝对路径

参数
[in]path_name
注解
空路径返回空

◆ 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)

返回文件Blake2b值

参数
[in]path_name路径名称
[out]Blake2b返回值(512位)

效验文件Blake2b值

参数
[in]path_name路径名称
[in]digest消息摘要(512位)

返回文件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
注解
a/b返回b,a/b/返回空

◆ GetFilePath()

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

返回文件所在路径

参数
[in]path_name必须传入右斜杠
注解
a/b返回a/,a/b/返回a/b/,a/b/c.txt返回a/b/

◆ GetFolderName()

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

返回路径所在文件夹名

参数
[in]path_name
注解
a/b返回a,a/b/返回空

◆ GetLastWriteTime()

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

返回文件最后修改时间

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

◆ GetParentPath()

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

返回上一级路径

参数
[in]path_name路径
返回值
失败返回原路径

◆ GetPathContent()

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

获取文件夹当前内容

参数
[in]path路径
[out]ret返回的目录
[in]regex正则表达式,例如 .(png|jpg|PNG)$
[in]folder是否包含目录
[in]file是否包含文件
注解
排除特定文件写法:^(?!a.png$|b.jpg$).*.(png|jpg)$
返回值
返回相对路径

◆ GetPathContentAll()

void dl::File::GetPathContentAll ( std::string_view path,
NTree< std::string > & ret )

获取文件夹所有内容

参数
[in]path路径
[out]ret返回的目录树

◆ GetPathFileAll() [1/2]

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

获取文件夹所有文件

参数
[in]path路径
[out]ret返回的文件名
[in]rule匹配规则
[in]recursion递归文件夹
返回值
返回相对路径

◆ GetPathFileAll() [2/2]

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递归文件夹
返回值
返回相对路径

◆ GetRelative()

std::string dl::File::GetRelative ( std::string_view path_name,
std::string_view path_base )

返回相对路径

参数
[in]path_name
[in]path_base
返回值
返回值带有./
注解
效率较低,可以使用String::ErasePath移除头部字符串

◆ GetStem()

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

返回文件名 不含后缀

参数
[in]path_name
注解
a/b返回b,a/b/返回空

◆ GetString()

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

按文本读文件

参数
[in]path_name路径名称

◆ InitFileSystem()

void dl::File::InitFileSystem ( )

◆ IsEmpty()

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

返回文件夹是否为空

参数
[in]path路径
返回值
不存在也返回空

◆ IsExist()

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

返回文件是否存在

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

◆ PathCurrent()

std::string dl::File::PathCurrent ( )

返回资源路径

注解
windows rw exe linux rw android rw PathStorage + "assets/"

◆ PathPrivate()

std::string dl::File::PathPrivate ( )

返回私有路径 rw

注解
windows AppData/LocalLow/dl_test linux android /data/user/0/com.dl.dl_test/files 安卓容量有限

◆ PathPublic()

std::string dl::File::PathPublic ( )

返回公共路径 rw

注解
windows ProgramData/ linux android /storage/emulated/0/

◆ PathRegular()

std::vector< std::string > dl::File::PathRegular ( )

返回常用路径

注解
盘符、我的文件、主目录等

◆ PathStorage()

std::string dl::File::PathStorage ( )

返回存储路径 rw

注解
windows AppData/Local/dl_test/ linux android /storage/emulated/0/Android/data/com.dl.dl_test/files

◆ PathStorageRoot()

std::string dl::File::PathStorageRoot ( )

返回存储路径根位置 rw

注解
windows AppData/Local/ linux android 与PathPublic等价

◆ PathTemp()

std::string dl::File::PathTemp ( )

返回临时路径 rw

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

◆ Rename()

bool dl::File::Rename ( std::string_view src,
std::string_view tar )

重命名文件

参数
[in]src路径名称
[in]tar修改为

◆ SaveBuffer()

bool dl::File::SaveBuffer ( BufferView buf,
std::string_view path_name )

将内存保存为文件

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

◆ SaveString() [1/2]

bool dl::File::SaveString ( BufferView buf,
std::string_view path_name )

将字符串保存为文件

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

◆ SaveString() [2/2]

bool dl::File::SaveString ( std::string_view str,
std::string_view path_name )

将字符串保存为文件

参数
[in]str字符串
[in]path_name保存路径(文件夹必须存在)

◆ Search()

std::string dl::File::Search ( std::string_view path,
std::string_view file_name )

从路径搜索文件

参数
[in]path字符串
[in]file_name文件名
返回值
返回完整路径,失败返回空

◆ Set()

std::ofstream dl::File::Set ( std::string_view path_name,
bool is_binary = true,
bool is_app = false )

打开一个文件(只写)

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