BoosterSeat  0.1
A C++ library that includes common utilities that are used in other projects.
filesystem.hpp
Go to the documentation of this file.
1 #ifndef FILESYSTEM_HPP_
2 #define FILESYSTEM_HPP_
3 
4 #include <stdint.h>
5 #include <string>
6 
7 namespace bst {
8 namespace filesystem {
9 namespace units {
11 
12 enum class Type { FILE, DIRECTORY };
13 } // namespace units
14 
25 bool doesFileExist(const std::string &file_path);
26 
34 void createFile(const std::string &file_path);
35 
47 void appendToFile(const std::string &file_path, const std::string &content,
48  const bool new_line_after = true);
49 
59 void overwriteFile(const std::string &file_path, const std::string &content);
60 
71 double getFileSize(const std::string &file_path,
72  units::Size size_unit = units::Size::BYTES);
73 
84 uintmax_t getFileSizeBytes(const std::string &file_path);
85 
92 void deleteFile(const std::string &file_path);
93 
103 bool doesDirectoryExist(const std::string &directory_path);
104 
114 void createDirectory(const std::string &directory_path);
115 
127 double getDirectorySize(const std::string &directory_path,
129 
141 bool hasWritePermission(const std::string &path);
142 
154 bool hasReadPermission(const std::string &path);
155 
162 void moveFile(const std::string &source_path,
163  const std::string &destination_path, bool overwrite = false);
164 
175 void copyFile(const std::string &source_path,
176  const std::string &destination_path, bool overwrite = false);
177 
184 std::string getFileName(const std::string &file_path);
185 
186 } // namespace filesystem
187 } // namespace bst
188 
189 #endif
Size
Definition: filesystem.hpp:10
Type
Definition: filesystem.hpp:12
void moveFile(const std::string &source_path, const std::string &destination_path, bool overwrite=false)
Move a file from one location to another.
void copyFile(const std::string &source_path, const std::string &destination_path, bool overwrite=false)
Move a file from one location to another.
double getDirectorySize(const std::string &directory_path, units::Size unit=units::Size::BYTES)
Get the size of a directory. Only includes regular files.
bool doesFileExist(const std::string &file_path)
Returns a boolean indicating whether or not the file exists. If it's a directory an exception will be...
std::string getFileName(const std::string &file_path)
Get the File Name from a path. Does not need to exist.
uintmax_t getFileSizeBytes(const std::string &file_path)
Get the size of a file.
void deleteFile(const std::string &file_path)
Delete a file.
void createFile(const std::string &file_path)
Create a File.
void overwriteFile(const std::string &file_path, const std::string &content)
Overwrite a files with a string.
double getFileSize(const std::string &file_path, units::Size size_unit=units::Size::BYTES)
Get the size of a file.
void appendToFile(const std::string &file_path, const std::string &content, const bool new_line_after=true)
Append a string to a file.
bool doesDirectoryExist(const std::string &directory_path)
Returns a boolean indicating whether or not the directory exists.
void createDirectory(const std::string &directory_path)
Create a Directory at the specified path.
bool hasReadPermission(const std::string &path)
If a program has read permissions to a file or directory, it will return true. Otherwise,...
bool hasWritePermission(const std::string &path)
If a program has write permissions to a file or directory, it will return true. Otherwise,...
Definition: filesystem.cpp:34