STTNet 0.7.0
Loading...
Searching...
No Matches
stt::file::FileTool Class Reference

提供文件操作的静态函数工具类 More...

#include <sttnet.h>

Inheritance diagram for stt::file::FileTool:
stt::file::File stt::file::LogFile

Static Public Member Functions

static bool createDir (const std::string &ddir, const mode_t &mode=0775)
 新建一个目录
 
static bool copy (const std::string &sourceFile, const std::string &objectFile)
 复制文件
 
static bool createFile (const std::string &filePath, const mode_t &mode=0666)
 新建一个文件
 
static size_t get_file_size (const std::string &fileName)
 获取文件大小
 

Detailed Description

Static helpers for directory creation, file creation, binary copying, and file-size lookup.

0.7.0 contract:
  • copy() copies raw bytes and returns false on open/write failure. It does not create the destination parent directory.
  • get_file_size() returns size_t; failure is std::numeric_limits<size_t>::max(), not a signed -1 value.

Member Function Documentation

◆ copy()

static bool stt::file::FileTool::copy ( const std::string & sourceFile,
const std::string & objectFile )
static

复制文件

Parameters
sourceFile源文件路径,可以绝对路径也可以相对路径
objectFile目标文件路径,可以绝对路径也可以相对路径
Returns
true 操作成功
false 操作失败
Note
不会自动创造不存在的路径

◆ createDir()

static bool stt::file::FileTool::createDir ( const std::string & ddir,
const mode_t & mode = 0775 )
static

新建一个目录

Parameters
ddir目录路径,可以绝对路径也可以相对路径
mode位掩码表示新建目录的权限(默认为0775 即rwx rwx r-x)
Returns
true 操作成功
false 操作失败

◆ createFile()

static bool stt::file::FileTool::createFile ( const std::string & filePath,
const mode_t & mode = 0666 )
static

新建一个文件

Parameters
filePath文件路径,可以绝对路径也可以相对路径
mode位掩码表示新建文件的权限(默认为0666 即rw- rw- rw-)
Returns
true 操作成功
false 操作失败
Note
会自动创造原本不存在的路径

◆ get_file_size()

static size_t stt::file::FileTool::get_file_size ( const std::string & fileName)
static

获取文件大小

Parameters
fileName文件名字(可以填绝对路径也可以填相对路径)
Returns
>=0 返回文件大小
-1 获取文件大小失败

The documentation for this class was generated from the following file: