forked from lioncash/ExtractData
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindFile.cpp
74 lines (56 loc) · 1.73 KB
/
FindFile.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
#include "StdAfx.h"
#include "Common.h"
#include "FindFile.h"
std::vector<YCString> CFindFile::DoFind(LPCTSTR base_path, LPCTSTR file_name)
{
HANDLE find_handle;
WIN32_FIND_DATA work;
TCHAR base_path_array[MAX_PATH];
TCHAR file_path_array[MAX_PATH];
//-- File Searching ------------------------------------------------------------------------
lstrcpy(base_path_array, base_path);
PathRemoveBackslash(base_path_array);
_stprintf(file_path_array, _T("%s\\%s"), base_path_array, file_name);
find_handle = FindFirstFile(file_path_array, &work);
if (find_handle != INVALID_HANDLE_VALUE)
{
do
{
// Add to the list of files found
YCString file_path = base_path_array;
file_path += _T("\\");
file_path += work.cFileName;
m_file_paths.push_back(file_path);
} while (FindNextFile(find_handle, &work));
FindClose(find_handle);
}
//-- Search Directory --------------------------------------------------------------------
_stprintf(file_path_array, _T("%s\\*.*"), base_path_array); // Search for all files
find_handle = FindFirstFile(file_path_array, &work);
if (find_handle != INVALID_HANDLE_VALUE)
{
do
{
if (!(work.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
// Is not a folder
continue;
}
if (lstrcmp(work.cFileName, _T(".")) == 0 || lstrcmp(work.cFileName, _T("..")) == 0)
{
// Is not current route
continue;
}
// Prepare directory discovery (add to the directory search path discovery)
_stprintf(file_path_array, _T("%s\\%s"), base_path_array, work.cFileName);
// Recursive call
DoFind(file_path_array, file_name);
} while (FindNextFile(find_handle, &work));
FindClose(find_handle);
}
return m_file_paths;
}
void CFindFile::Clear()
{
m_file_paths.clear();
}