-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFilesRead.cpp
76 lines (72 loc) · 1.89 KB
/
FilesRead.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
// Files Reading functions
// @author: [email protected]
// @date: 2015/09/20
#include "stdafx.h"
#include "FilesRead.h"
void GetFiles(string path, string exd, vector<string>& files)
{
long hFile = 0;
struct _finddata_t fileinfo;
string pathName, exdName;
if (0 != strcmp(exd.c_str(), ""))
{
exdName = "/*" + exd;
}
else
{
exdName = "/*";
}
if ((hFile = long(_findfirst(pathName.assign(path).append(exdName).c_str(), &fileinfo))) != -1)
{
do
{
if((fileinfo.attrib & _A_SUBDIR))
{
if(strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
GetFiles(pathName.assign(path).append("/").append(fileinfo.name), exd, files);
}
else
{
if(strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
//cout << pathName.assign(path).append("/").append(fileinfo.name) << endl;
files.push_back(pathName.assign(path).append("/").append(fileinfo.name));
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
void GetLabelInfo(string path, map<string, InfoStruct>& infos)
{
ifstream fin(path, ios::in);
char line[1024] = {0};
string personindex;
InfoStruct tmp_info;
while (fin.getline(line, sizeof(line)))
{
stringstream word(line);
word >> personindex;
if (-1 == personindex.find("Sub.")) continue;
tmp_info.Index = personindex;
word >> tmp_info.OriImage;
word >> tmp_info.grade;
infos.insert(pair<string, InfoStruct>(tmp_info.Index, tmp_info));
}
fin.clear();
fin.close();
}
vector<string> str_split(string str, string pattern)
{
vector<string> ret;
if (pattern.empty()) return ret;
size_t start = 0;
size_t index = str.find_first_of(pattern, 0);
while (index != str.npos) {
if (start != index) {
ret.push_back(str.substr(start, index - start));
start = index + 1;
index = str.find_first_of(pattern, start);
}
}
if (!str.substr(start).empty()) ret.push_back(str.substr(start));
return ret;
}