dl
dl_file.h
浏览该文件的文档.
1
29#pragma once
30
31#include <string>
32#include <vector>
33#include <fstream>
34
35#include "base/dl_tree.h"
36#include "memory/dl_buffer.h"
38namespace dl::File
39{
40
41
50void GetPathFileAll(std::string_view path, std::vector<std::string>& ret,
51 std::string_view regex = "", bool recursion = true);
52
55{
56 std::vector<std::string> _vecFmt;
57 std::vector<std::string> _vecFilter;
58 std::vector<std::string> _vecFilterFolder;
59};
60
68void GetPathFileAll(std::string_view path, std::vector<std::string>& ret,
69 const SearchRule& rule, bool recursion = true);
70
81void GetPathContent(std::string_view path, std::vector<std::string>& ret,
82 std::string_view regex = "", bool folder = true, bool file = true);
83
89void GetPathContentAll(std::string_view path, NTree<std::string>& ret);
90
99FILE* GetFile(std::string_view path_name, bool is_binary = true);
100
101std::ifstream Get(std::string_view path_name, bool is_binary = true);
102
112std::ofstream Set(std::string_view path_name,
113 bool is_binary = true,
114 bool is_app = false);
115
122bool ConvertMb2U8(std::string_view path_name, std::string_view out);
123
128std::string GetString(std::string_view path_name);
129
135Buffer GetBuffer(std::string_view path_name);
136
142Buffer GetBuffer(std::ifstream& ifs);
143
149bool SaveBuffer(BufferView buf, std::string_view path_name);
150
156bool SaveString(BufferView buf, std::string_view path_name);
157
163bool SaveString(std::string_view str, std::string_view path_name);
164
165
167//* @brief 返回文件Blake2b值
168//* @param[in] path_name 路径名称
169//* @param[out] Blake2b 返回值(512位)
170//*/
171//bool HashBlake2b(std::string_view path_name, Crypto::Blake2b& blake2b);
172//
174//* @brief 效验文件Blake2b值
175//* @param[in] path_name 路径名称
176//* @param[in] digest 消息摘要(512位)
177//*/
178//bool HashBlake2bCheck(std::string_view path_name, const Crypto::Blake2b& digest);
179
185uint32_t GetCrc32(std::string_view path_name);
186
187
193bool IsExist(std::string_view path_name);
194
200bool IsEmpty(std::string_view path);
201
208bool Delete(std::string_view path_name, bool all = false);
209
215void DeleteContent(std::string_view path_name);
216
222bool Rename(std::string_view src, std::string_view tar);
223
230std::string Search(std::string_view path, std::string_view file_name);
231
232enum class CopyMode
233{
237};
238
245bool Copy(std::string_view source, std::string_view target,
246 CopyMode mode = CopyMode::NONE, bool recursion = false);
247
253std::string GetExtension(std::string_view path_name, bool has_dot = false);
254
260std::string GetFileName(std::string_view path_name);
266std::string GetStem(std::string_view path_name);
272std::string GetFolderName(std::string_view path_name);
278std::string GetFilePath(std::string_view path_name);
285std::string GetAbsolute(std::string_view path_name);
293std::string GetRelative(std::string_view path_name, std::string_view path_base);
299std::string GetParentPath(std::string_view path_name);
300
306bool CreateFolder(std::string_view path);
307
313time_t GetLastWriteTime(std::string_view path_name);
314
315
316
328bool CheckPathFileModified(std::string_view path_name, const SearchRule& rule, std::string_view cache, bool update);
329
330//----------------------------常见路径----------------------------
337std::string PathCurrent();
343std::string PathTemp();
350std::string PathStorage();
357std::string PathStorageRoot();
365std::string PathPrivate();
372std::string PathPublic();
373
378std::vector<std::string> PathRegular();
379
381//string LastWriteTimeTostring(const std::file_time_type& ftime)
382//{
383// string str;
384// std::time_t cftime = file_time_type::clock::time_point(ftime).time_since_epoch();
385// std::time_t cftime = std::chrono::system_clock::to_time_t();
386// return std::asctime(std::localtime(&cftime));
387//}
388
390
392namespace Lua
393{
401 inline std::vector<std::string> lua_GetPathFileAll_3(std::string_view path, std::string_view regex /*= ""*/, bool recursion /*= true*/)
402 {
403 std::vector<std::string> ret;
404 GetPathFileAll(path, ret, regex, recursion);
405 return ret;
406 }
407
413 inline std::vector<std::string> lua_GetPathFileAll_2(std::string_view path,
414 std::string_view regex)
415 {
416 std::vector<std::string> ret;
417 GetPathFileAll(path, ret, regex, true);
418 return ret;
419 }
420
425 inline std::vector<std::string> lua_GetPathFileAll_1(std::string_view path)
426 {
427 std::vector<std::string> ret;
428 GetPathFileAll(path, ret, "", true);
429 return ret;
430 }
431}
432
433}
N叉树
表示一段内存
N叉树
文件系统lua接口
std::vector< std::string > lua_GetPathFileAll_1(std::string_view path)
获取文件夹所有文件
std::vector< std::string > lua_GetPathFileAll_2(std::string_view path, std::string_view regex)
获取文件夹所有文件
std::vector< std::string > lua_GetPathFileAll_3(std::string_view path, std::string_view regex, bool recursion)
获取文件夹所有文件
文件系统
void DeleteContent(std::string_view path_name)
删除文件夹内容,但不删除文件夹
bool Copy(std::string_view source, std::string_view target, CopyMode mode=CopyMode::NONE, bool recursion=false)
复制文件或文件夹
bool CheckPathFileModified(std::string_view path_name, const SearchRule &rule, std::string_view cache, bool update)
判断路径内的文件是否有修改(包括增加、删除文件)
uint32_t GetCrc32(std::string_view path_name)
返回文件Blake2b值
FILE * GetFile(std::string_view path_name, bool is_binary=true)
打开一个文件(只读),可能从压缩包内读取
std::string GetStem(std::string_view path_name)
返回文件名 不含后缀
std::string PathStorageRoot()
返回存储路径根位置 rw
void GetPathFileAll(std::string_view path, std::vector< std::string > &ret, std::string_view regex="", bool recursion=true)
获取文件夹所有文件
bool SaveString(BufferView buf, std::string_view path_name)
将字符串保存为文件
std::vector< std::string > PathRegular()
返回常用路径
bool IsExist(std::string_view path_name)
返回文件是否存在
@ NONE
文件已存在,则返回失败
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)
获取文件夹所有内容
bool Rename(std::string_view src, std::string_view tar)
重命名文件
std::string GetExtension(std::string_view path_name, bool has_dot=false)
返回文件后缀
std::ifstream Get(std::string_view path_name, bool is_binary=true)
std::string PathCurrent()
返回资源路径
std::string GetFolderName(std::string_view path_name)
返回路径所在文件夹名
std::string PathPrivate()
返回私有路径 rw
std::string Search(std::string_view path, std::string_view file_name)
从路径搜索文件
bool SaveBuffer(BufferView buf, std::string_view path_name)
将内存保存为文件
std::string GetAbsolute(std::string_view path_name)
返回绝对路径
time_t GetLastWriteTime(std::string_view path_name)
返回文件最后修改时间
bool ConvertMb2U8(std::string_view path_name, std::string_view out)
将文本文件从mb转到utf-8
bool IsEmpty(std::string_view path)
返回文件夹是否为空
std::string GetFilePath(std::string_view path_name)
返回文件所在路径
std::string PathPublic()
返回公共路径 rw
std::string GetParentPath(std::string_view path_name)
返回上一级路径
bool Delete(std::string_view path_name, bool all=false)
删除文件或路径
std::ofstream Set(std::string_view path_name, bool is_binary=true, bool is_app=false)
打开一个文件(只写)
bool CreateFolder(std::string_view path)
创建目录
std::string PathTemp()
返回临时路径 rw
void InitFileSystem()
std::string GetRelative(std::string_view path_name, std::string_view path_base)
返回相对路径
std::string GetString(std::string_view path_name)
按文本读文件
std::string PathStorage()
返回存储路径 rw
Buffer GetBuffer(std::string_view path_name)
返回文件内存
std::string GetFileName(std::string_view path_name)
返回文件名 包含后缀
过滤规则,不兼容大小写
std::vector< std::string > _vecFmt
要求的格式 png
std::vector< std::string > _vecFilterFolder
过滤的文件夹 .work
std::vector< std::string > _vecFilter
过滤的文件 1.txt