common_util
|
The functions and classes about filesystem, such as file and directory operations. More...
Go to the source code of this file.
Classes | |
class | cutl::file_guard |
The file guard class to manage the FILE pointer automatically. file_guard object can close the FILE pointer automatically when his scope is exit. More... | |
Functions | |
std::string | cutl::filetype_flag (filetype type) |
Get the file type flag string. | |
bool | cutl::createfile (const filepath &path) |
Create a new file. | |
bool | cutl::createlink (const filepath &referenece, const filepath &filepath) |
Create a symbolic link or shortcut. | |
bool | cutl::createdir (const filepath &path, bool recursive=false) |
Create a new directory. | |
bool | cutl::removefile (const filepath &path) |
Remove a regular file or symbolic link(shortcut on windows). | |
bool | cutl::removedir (const filepath &path, bool recursive=false) |
Remove a directory. | |
std::string | cutl::readtext (const filepath &path, uint64_t max_read_size=4096) |
Read the text content of a file. | |
bool | cutl::writetext (const filepath &path, const std::string &content) |
Write the text content to a file. | |
uint64_t | cutl::filesize (const filepath &filepath, bool link_target=false) |
Get the size of a file. | |
uint64_t | cutl::dirsize (const filepath &dirpath) |
Get the size of a directory, include all files and subdirectories. | |
filevec | cutl::list_files (const filepath &dirpath, filetype type=filetype::all, bool recursive=false) |
List all files in a directory. | |
filevec | cutl::find_files (const filepath &dirpath, const std::string &name, bool recursive=false) |
Find all files in a directory by name. | |
filevec | cutl::find_files_by_extension (const filepath &dirpath, const std::string &extension, bool recursive=false) |
Find all files in a directory by extension. | |
bool | cutl::copyfile (const filepath &srcpath, const filepath &dstpath, bool attributes=false) |
Copy a file or symbolic link(shortcut on windows). | |
bool | cutl::copydir (const filepath &srcdir, const filepath &dstdir) |
Copy a directory recursively. | |
The functions and classes about filesystem, such as file and directory operations.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations.
Copy a directory recursively.
srcdir | the filepath of the source directory to be copied |
dstdir | the filepath of the destination directory to be copied to |
Copy a file or symbolic link(shortcut on windows).
srcpath | the filepath of the source file or symbolic link to be copied |
dstpath | the filepath of the destination file or symbolic link to be copied to |
attributes | whether to copy the file attributes, default is false. If true, means copy the file attributes, like the 'cp -p' command. |
bool cutl::createdir | ( | const filepath & | path, |
bool | recursive = false ) |
Create a new directory.
path | the filepath of the new directory to be created |
recursive | whether to create parent directories, default is false. If true, means create parent directories if not exist, like the 'mkdir -p' command. |
bool cutl::createfile | ( | const filepath & | path | ) |
Create a new file.
path | the filepath of the new file to be created |
Create a symbolic link or shortcut.
referenece | the real path referenced by the symbolic link or shortcut |
filepath | the filepath of the symbolic link or shortcut to be created |
uint64_t cutl::dirsize | ( | const filepath & | dirpath | ) |
Get the size of a directory, include all files and subdirectories.
dirpath | the filepath of the directory to be checked |
uint64_t cutl::filesize | ( | const filepath & | filepath, |
bool | link_target = false ) |
Get the size of a file.
filepath | the filepath of the file to be checked |
link_target | whether to get the size of the file pointed by symbolic link, default is false. If link_target is true, the function will get the size of the file pointed by symbolic link, not the symbolic link itself. |
std::string cutl::filetype_flag | ( | filetype | type | ) |
Get the file type flag string.
type | file type |
filevec cutl::find_files | ( | const filepath & | dirpath, |
const std::string & | name, | ||
bool | recursive = false ) |
Find all files in a directory by name.
dirpath | the filepath of the directory to be searched |
name | the name of the file to be found, substring match is supported. |
recursive | whether to search the whole directory recursively, default is false. If true, means search the whole directory recursively, like the 'find' command. |
filevec cutl::find_files_by_extension | ( | const filepath & | dirpath, |
const std::string & | extension, | ||
bool | recursive = false ) |
Find all files in a directory by extension.
dirpath | the filepath of the directory to be searched |
extension | the extension of the file to be found, with dot, like ".txt". |
recursive | whether to search the whole directory recursively, default is false. If true, means search the whole directory recursively, like the 'find' command. |
filevec cutl::list_files | ( | const filepath & | dirpath, |
filetype | type = filetype::all, | ||
bool | recursive = false ) |
List all files in a directory.
dirpath | the filepath of the directory to be listed |
type | file type to be listed, default is all types. |
recursive | whether to list the whole directory recursively, default is false. If true, means list the whole directory recursively, like the 'ls -R' command. |
std::string cutl::readtext | ( | const filepath & | path, |
uint64_t | max_read_size = 4096 ) |
Read the text content of a file.
path | the filepath of the file to be read |
max_read_size | the maximum size to be read, default is 4096 bytes. |
If the file size is larger than max_read_size, only the first max_read_size bytes will be read. otherwise, the whole file will be read.
bool cutl::removedir | ( | const filepath & | path, |
bool | recursive = false ) |
Remove a directory.
path | the filepath of the directory to be removed |
recursive | whether to remove the whole directory recursively, default is false. If true, means remove the whole directory recursively, like the 'rm -rf' command. |
bool cutl::removefile | ( | const filepath & | path | ) |
Remove a regular file or symbolic link(shortcut on windows).
path | the filepath of the file or symbolic link to be removed |
bool cutl::writetext | ( | const filepath & | path, |
const std::string & | content ) |
Write the text content to a file.
path | the filepath of the file to be written |
content | text content to be written to the file |