dl
dl_file.h
浏览该文件的文档.
1
29#pragma once
30
31//#include <filesystem>
32#include <string>
33#include <vector>
34#include <fstream>
35
36#include "base/dl_tree.h"
37#include "memory/dl_buffer.h"
38
39namespace dl::File
40{
41
42
51void GetPathFileAll(std::string_view path, std::vector<std::string>& ret,
52 std::string_view regex = "", bool recursion = true);
53
64void GetPathContent(std::string_view path, std::vector<std::string>& ret,
65 std::string_view regex = "", bool folder = true, bool file = true);
66
72void GetPathContentAll(std::string_view path, NTree<std::string>& ret);
73
82FILE* GetFile(std::string_view path_name, bool is_binary = true);
83
84std::ifstream Get(std::string_view path_name, bool is_binary = true);
85
95std::ofstream Set(std::string_view path_name,
96 bool is_binary = true,
97 bool is_app = false);
98
105bool ConvertMb2U8(std::string_view path_name, std::string_view out);
106
111std::string GetString(std::string_view path_name);
112
118Buffer GetBuffer(std::string_view path_name);
119
125Buffer GetBuffer(std::ifstream& ifs);
126
132bool SaveBuffer(BufferView buf, std::string_view path_name);
133
139bool SaveString(BufferView buf, std::string_view path_name);
140
146bool SaveString(std::string_view str, std::string_view path_name);
147
148
150//* @brief 返回文件Blake2b值
151//* @param[in] path_name 路径名称
152//* @param[out] Blake2b 返回值(512位)
153//*/
154//bool HashBlake2b(std::string_view path_name, Crypto::Blake2b& blake2b);
155//
157//* @brief 效验文件Blake2b值
158//* @param[in] path_name 路径名称
159//* @param[in] digest 消息摘要(512位)
160//*/
161//bool HashBlake2bCheck(std::string_view path_name, const Crypto::Blake2b& digest);
162
168uint32_t GetCrc32(std::string_view path_name);
169
170
176bool IsExist(std::string_view path_name);
177
184bool Delete(std::string_view path_name, bool all = false);
185
191void DeleteContent(std::string_view path_name);
192
198bool Rename(std::string_view src, std::string_view tar);
199
206std::string Search(std::string_view path, std::string_view file_name);
207
208enum class CopyMode
209{
213};
214
221bool Copy(std::string_view source, std::string_view target,
222 CopyMode mode = CopyMode::NONE, bool recursion = false);
223
229std::string GetExtension(std::string_view path_name, bool has_dot = false);
230
236std::string GetFilename(std::string_view path_name);
242std::string GetStem(std::string_view path_name);
248std::string GetFolderName(std::string_view path_name);
254std::string GetFilePath(std::string_view path_name);
261std::string GetAbsolute(std::string_view path_name);
268std::string GetRelative(std::string_view path_name, std::string_view path_base);
269
275bool CreateFolder(std::string_view path);
276
282time_t GetLastWriteTime(std::string_view path_name);
283
284
285
297bool CheckPathFileModified(std::string_view path_name, std::string_view regex, std::string_view cache, bool update);
298
299//----------------------------常见路径----------------------------
306std::string PathCurrent();
312std::string PathTemp();
319std::string PathStorage();
320std::string PathStorageRoot();
328std::string PathPrivate();
335std::string PathPublic();
336
337
339//string LastWriteTimeTostring(const std::file_time_type& ftime)
340//{
341// string str;
342// std::time_t cftime = file_time_type::clock::time_point(ftime).time_since_epoch();
343// std::time_t cftime = std::chrono::system_clock::to_time_t();
344// return std::asctime(std::localtime(&cftime));
345//}
346
348
349}
表示一段内存
void DeleteContent(std::string_view path_name)
删除文件夹内容,但不删除文件夹
bool Copy(std::string_view source, std::string_view target, CopyMode mode=CopyMode::NONE, bool recursion=false)
复制文件或文件夹
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()
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)
将字符串保存为文件
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 CheckPathFileModified(std::string_view path_name, std::string_view regex, std::string_view cache, bool update)
判断路径内的文件是否有修改(包括增加、删除文件)
std::string GetFilePath(std::string_view path_name)
返回文件所在路径
std::string PathPublic()
返回公共路径 rw
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 GetFilename(std::string_view path_name)
返回文件名
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::span< std::byte > BufferView
std::vector< std::byte > Buffer