-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilesystem.h
More file actions
77 lines (66 loc) · 2.17 KB
/
filesystem.h
File metadata and controls
77 lines (66 loc) · 2.17 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef FILESYSTEM_H
#define FILESYSTEM_H
#include <string>
#include <vector>
class FileSystem {
public:
/**
* check a file or a directory exists
* @param[in] path a file path or a directory path
* @return true if path exists else false
*/
static bool isExists(const std::string& path);
/**
* create a directory if not exists, **the parent directory must exist**
* @param[in] dp directory path
* @reutrn true if create success else false
*/
static bool makeDir(const std::string& dp);
/**
* delete a file if exists
* if the file doesn't exists, nothing will be done and return true
* @param[in] fp full file path in filesystem
* @return true if deleted else false
*/
static bool deleteFile(const std::string& fp);
/**
* move file from src to dst, both parent directory of src and dst must exists
* @param[in] src file source
* @param[in] dst file destination
* @return true if moved else false
*/
static bool moveFile(const std::string& src, const std::string& dst);
/**
* get file name from file path
* /path/to/xxx.yyy -> xxx or xxx.yyy -> xxx
* @param[in] fp file path
* return file name without extension name
*/
static std::string getFileName(const std::string& fp);
/**
* get file extension name from file path
* /path/to/xxx.yyy -> yyy or xxx.yyy -> yyy
* @param[in] fp file path
* @return file extension name
*/
static std::string getFileExt(const std::string& fp);
/**
* get file list in a directory with specific extension name
* @param[in] dp directory path
* @param[in] ext extension name
* @param[out] fn files
* @paran[in] limit numbers of files to load
* @return true if success else false
*/
static bool readDir(const std::string& dp, const std::string& ext, \
std::vector<std::string>& fn, int limit=0);
static bool FileSystem::readDirwithpath(const std::string& dp, const std::string& ext,
std::vector<std::string>& fn, int limit=0);
/**
* join path for part1 and part2
* @param[in] part1, part2 filesystem path
* @return filesystem path for part1/part2
*/
static std::string join(const std::string &part1, const std::string &part2);
};
#endif // FILESYSTEM_H