-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdafx.cpp
120 lines (85 loc) · 2.84 KB
/
stdafx.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// stdafx.cpp : source file that includes just the standard includes
// CAPSImg.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
#ifdef WIN32
#include <direct.h>
std::vector<std::string> local_DirectoryList(const std::string& pPath, const std::string& pExtension) {
WIN32_FIND_DATA fdata;
HANDLE dhandle;
std::vector<std::string> results;
char path[2000];
_getcwd(path, 2000);
// Build the file path
std::string finalPath;
if (pPath.size())
finalPath += pPath;
finalPath += "/*";
finalPath += pExtension;
if ((dhandle = FindFirstFile(finalPath.c_str(), &fdata)) == INVALID_HANDLE_VALUE) {
return results;
}
results.push_back(std::string(fdata.cFileName));
while (1) {
if (FindNextFile(dhandle, &fdata)) {
results.push_back(std::string(fdata.cFileName));
}
else {
if (GetLastError() == ERROR_NO_MORE_FILES) {
break;
}
else {
FindClose(dhandle);
return results;
}
}
}
FindClose(dhandle);
return results;
}
#else
#include <dirent.h>
#include <algorithm>
std::string findType;
int file_select(const struct dirent *entry) {
std::string name = entry->d_name;
std::transform(name.begin(), name.end(), name.begin(), ::toupper);
if (name.find(findType) == std::string::npos)
return false;
return true;
}
std::vector<std::string> local_DirectoryList(const std::string& pPath, const std::string& pExtension) {
struct dirent **directFiles;
std::vector<std::string> results;
// Build the file path
std::string finalPath;
finalPath += pPath;
finalPath += "/";
findType = pExtension;
transform(findType.begin(), findType.end(), findType.begin(), ::toupper);
int count = scandir(finalPath.c_str(), (dirent***)&directFiles, file_select, 0);
for (int i = 0; i < count; ++i) {
results.push_back(std::string(directFiles[i]->d_name));
}
transform(findType.begin(), findType.end(), findType.begin(), ::tolower);
count = scandir(finalPath.c_str(), (dirent***)&directFiles, file_select, 0);
for (int i = 0; i < count; ++i) {
results.push_back(std::string(directFiles[i]->d_name));
}
return results;
}
void GetLocalTime(LPSYSTEMTIME lpSystemTime)
{
time_t t = time(NULL);
struct tm *tp = localtime(&t);
lpSystemTime->wYear = tp->tm_year + 1900;
lpSystemTime->wMonth = tp->tm_mon + 1;
lpSystemTime->wDayOfWeek = tp->tm_wday;
lpSystemTime->wDay = tp->tm_mday;
lpSystemTime->wHour = tp->tm_hour;
lpSystemTime->wMinute = tp->tm_min;
lpSystemTime->wSecond = tp->tm_sec;
// we don't have milliseconds in struct tm
lpSystemTime->wMilliseconds = 0;
}
#endif