18 size_t pos = file.rfind(
'/', file.length() - 2);
19 name = file.substr(pos + 1);
20 std::transform(
name.begin(),
name.end(),
name.begin(), ::tolower);
25 #if defined(HAVE_DIRENT_H) && defined(HAVE_OPENDIR) && defined(HAVE_READDIR_R) && defined(HAVE_CLOSEDIR) && defined(HAVE_DT_DIR)
28 #elif defined (_WIN32)
32 #error No support for recursive folder traversal
36 if (((folder.length() == 0) || (folder.compare(
".") == 0))
38 || ((folder.compare(1, 2, std::string(
":\\")) != 0) && (folder.at(0) !=
'~'))
40 || ((folder.at(0) !=
'/') && (folder.at(0) !=
'~'))
45 if (folder.length() > 1)
46 path += folder.substr(1);
47 }
else if (folder.at(0) ==
'~') {
50 std::cout <<
"Home: " <<
path << std::endl;
51 if (folder.length() > 1)
52 path += folder.substr(1);
58 size_t pos =
path.find(
'\\');
59 while (pos != std::string::npos) {
61 pos =
path.find(
'\\');
65 if (
path.length() > 1)
66 last =
path.rfind(
'/',
path.length() - 2);
68 if (
name.back() ==
'/')
71 std::transform(
name.begin(),
name.end(),
name.begin(), ::tolower);
73 if (
path.back() !=
'/')
103 size_t last =
path.rfind(
'/',
path.length() - 2);
104 std::string parent =
path.substr(0, last);
105 if (parent.length() == 0)
112 for (
unsigned long i = 0; i <
fileCount(); i++) {
123 std::vector<std::string> foundFiles, foundFolders;
129 std::vector<std::string>::iterator it = foundFiles.begin();
130 while (it != foundFiles.end()) {
131 size_t pos = it->rfind(
'/', it->length() - 2);
132 if (it->at(pos + 1) ==
'.')
133 it = foundFiles.erase(it);
138 it = foundFolders.begin();
139 while (it != foundFolders.end()) {
140 size_t pos = it->rfind(
'/', it->length() - 2);
141 if (it->at(pos + 1) ==
'.')
142 it = foundFolders.erase(it);
148 std::sort(foundFiles.begin(), foundFiles.end());
149 std::sort(foundFolders.begin(), foundFolders.end());
151 for (
unsigned long i = 0; i < foundFiles.size(); i++)
152 files.emplace_back(
File(foundFiles.at(i)));
154 for (
unsigned long i = 0; i < foundFolders.size(); i++)
163 std::vector<std::string>& foundFolders) {
165 struct dirent* ep =
nullptr;
168 pakDir = opendir(
path.c_str());
169 if (pakDir !=
nullptr) {
170 readdir_r(pakDir, &entry, &ep);
171 while (ep !=
nullptr) {
172 if ((strcmp(
".", ep->d_name) != 0)
173 && (strcmp(
"..", ep->d_name) != 0)) {
174 std::string tmp(
path);
175 if (tmp.back() !=
'/')
178 if (ep->d_type == DT_DIR) {
179 if (tmp.back() !=
'/')
181 foundFolders.push_back(std::string(tmp));
183 foundFiles.push_back(std::string(tmp));
186 readdir_r(pakDir, &entry, &ep);
196 #elif defined(USE_FINDFILE)
199 std::vector<std::string>& foundFolders) {
200 std::string tmp(
path);
204 HANDLE hFind = FindFirstFile(tmp.c_str(), &fd);
205 if (hFind ==
nullptr)
210 s = s +
"/" + fd.cFileName;
211 if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
212 foundFolders.push_back(s);
214 foundFiles.push_back(s);
215 }
while (FindNextFile(hFind, &fd) != 0);
225 for (
auto& f :
files) {
std::string name
Only last part of path.
Folder & getFolder(unsigned long i)
String handling utilities.
unsigned long folderCount()
Folder(std::string folder, bool listDotFiles=false)
static LogLevel & get(int level)
std::vector< File > files
unsigned long fileCount()
bool stringEndsWith(std::string s, std::string suffix, bool casesensitive=false)
std::vector< Folder > folders
std::string getCurrentWorkingDirectory()
Recursive file-system walking utilities.
std::string path
Full path, with name and '/' at end.
void executeRemoveFiles(std::function< bool(File &f)> func)
File & getFile(unsigned long i)
void findFilesEndingWith(std::vector< File > &found, std::string end, bool casesensitive=false)
std::string getHomeDirectory()
int readFolderItems(std::vector< std::string > &foundFiles, std::vector< std::string > &foundFolders)