赞
踩
base::FilePath path = base::FilePath(L"C:\T.txt");
FilePath AddExtension(StringPieceType extension) ;//增加扩展名
path. AddExtension(L"ZIP"); // C:\T.txt.RAR
base/files/file.h
base::File file = base::File(const FilePath& path, uint32_t flags);
flags取值(可以用 “|”)
enum Flags { FLAG_OPEN = 1 << 0, // Opens a file, only if it exists. FLAG_CREATE = 1 << 1, // Creates a new file, only if it does not already exist. FLAG_OPEN_ALWAYS = 1 << 2, // May create a new file. FLAG_CREATE_ALWAYS = 1 << 3, // May overwrite an old file. FLAG_OPEN_TRUNCATED = 1 << 4, // Opens a file and truncates it, only if it exists. FLAG_READ = 1 << 5, FLAG_WRITE = 1 << 6, FLAG_APPEND = 1 << 7, FLAG_EXCLUSIVE_READ = 1 << 8, // EXCLUSIVE is opposite of Windows SHARE. FLAG_EXCLUSIVE_WRITE = 1 << 9, FLAG_ASYNC = 1 << 10, FLAG_TEMPORARY = 1 << 11, // Used on Windows only. FLAG_HIDDEN = 1 << 12, // Used on Windows only. FLAG_DELETE_ON_CLOSE = 1 << 13, FLAG_WRITE_ATTRIBUTES = 1 << 14, // Used on Windows only. FLAG_SHARE_DELETE = 1 << 15, // Used on Windows only. FLAG_TERMINAL_DEVICE = 1 << 16, // Serial port flags. FLAG_BACKUP_SEMANTICS = 1 << 17, // Used on Windows only. FLAG_EXECUTE = 1 << 18, // Used on Windows only. FLAG_SEQUENTIAL_SCAN = 1 << 19, // Used on Windows only. FLAG_CAN_DELETE_ON_CLOSE = 1 << 20, // Requests permission to delete a file via DeleteOnClose() (Windows only). See DeleteOnClose() for details. };
文件打开 :(FLAG_OPEN)
文件打开并读取 :(FLAG_OPEN |FLAG_READ)
文件关闭后自动删除 :(FLAG_OPEN |FLAG_READ|FLAG_DELETE_ON_CLOSE)
文件手动选择关闭后是否删除 :(FLAG_OPEN |FLAG_READ|FLAG_CAN_DELETE_ON_CLOSE)
Close()之前设置DeleteOnClose(bool delete_on_close);
delete_on_close=true;// 关闭后删除
delete_on_close=false;// 关闭后不删除
Close();不需要主动调用,在File类的析构函数已调用改方法。
base/files/file_util.h
bool PathExists(const FilePath& path);//判断某个文件夹是否存在,不存在返回false,存在返回ture
base/files/file_util.h
创建一个文件夹目录
bool CreateDirectory(const FilePath& full_path);
full_path = base::FilePath(L"C:\\123\\456\\"); // c:\123\456\
CreateDirectory(full_path);//在c盘下创建123文件夹,并在123文件夹下创建456文件夹
去掉后面的“\”,效果一样
full_path = base::FilePath(L"C:\\123\\456"); // c:\123\456
CreateDirectory(full_path);//在c盘下创建123文件夹,并在123文件夹下创建456文件夹
FilePath MakeAbsoluteFilePath(const FilePath& input);// 将相对路径转换为绝对路径
base::MakeAbsoluteFilePath(base::FilePath(L"\\angledata\\"));
程序在D盘123目录运行 返回 D:\angledata
程序在C盘456目录运行 返回 C:\angledata\
int64_t ComputeDirectorySize(const FilePath& root_path);// 返回给定路径目录大小
base::ComputeDirectorySize(base::FilePath(L"C:\123\"))
bool DeleteFile(const FilePath& path, bool recursive);
如果path为目录,则 recursive 必须等于 true,不然无法删除文件夹。
如果path为文件,则 recursive 是否为true,都不会删除同目录下的其他文件和目录。
bool DeleteFileRecursively(const FilePath& path);
//等价于
bool DeleteFile(const FilePath& path, true);
bool DeleteFileAfterReboot(const FilePath& path);
//重启后删除文件,文件或目录必须位于"TMP" 文件下,目录必须为空
bool Move(const FilePath& from_path, const FilePath& to_path);
from_path 可以是文件或者目录;
to_path 必须是目录;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。