-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileUtil.h
52 lines (40 loc) · 1.81 KB
/
FileUtil.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include <string>
#include <vector>
namespace FileUtil{
// Return list of files in a directory
// throw an exception if directory doesn't exist
// Non-recursive
std::vector<std::string> getFilesInDirectory(const std::string& directory);
// Same but with directories
std::vector<std::string> getDirectoriesInDirectory(const std::string& directory);
// Get file contents as binary
// Throw exception if it DNE
std::string getFileContents(const std::string& path);
// Or set the file contents as binary
void setFileContents(const std::string& path, const std::string& contents);
// Create a temporary file with specified contents
// return a string to the new file
std::string createTemporaryFile(const std::string& contents);
// Return file extension. input: "bla.cpp", return: "cpp"
std::string extractFileExtension(const std::string& filename);
// Recursively create a directory if it does not exist. If this isn't
// possible, throw an exception
void ensureDirectoryExists(const std::string& path);
// Similar to above, but create a file instead if it doesn't exist
void ensureFileExists(const std::string& path);
// Check if file exists
bool fileExists(const std::string& path);
// Recursively destroy directory, but throw exception if it doesn't exist
void destroyDirectory(const std::string& path);
// Destroy a file, throw an exception if it doesn't exist
void destroyFile(const std::string& path);
// Same as the previous two, but destruction
// Recursively destroy directory if it exists
void ensureDirectoryDoesNotExist(const std::string& path);
// And same but with file. Not recursive though, because that doesn't make
// sense in this context
void ensureFileDoesNotExist(const std::string& path);
// Get the path of the parent element
std::string getParentPath(std::string path);
}