-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFiles.cpp
More file actions
42 lines (37 loc) · 1.62 KB
/
Copy pathFiles.cpp
File metadata and controls
42 lines (37 loc) · 1.62 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
//Files.cpp
#include "Files.h"
#include <iostream>
#include <dirent.h>
namespace sdlUtility {
namespace Files {
/// Used to return a list of available directories and files at the specified path.
/** @param Path Path to browse to.
@param FileType Optional file type to limit the results to within the directory. */
std::vector<std::string> GetDirectoryList(std::string Path, std::string FileType) {
std::vector<std::string> DirectoryList;
DIR *Directory = opendir(Path.c_str());
if (Directory) {
dirent *Entry = readdir(Directory);
while (Entry) {
std::string Name = Entry->d_name;
int Length = Entry->d_namlen;
if (Name != "." and Name != "..") {
if (FileType != "") {
int TypeLength = FileType.size();
if (Length > TypeLength) {
if (Name.substr(Length-TypeLength, TypeLength) == FileType) {
DirectoryList.push_back(Name);
}
}
} else {
DirectoryList.push_back(Name);
}
}
Entry = readdir(Directory);
}
closedir(Directory);
} else std::cerr << "(Physics/Functions.cpp) GetDirectoryList(): Directory '" << Path << "' could not be initialized correctly." << std::endl;
return DirectoryList;
}
}
}