-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanNSortDirectory.cpp
More file actions
82 lines (74 loc) · 1.71 KB
/
Copy pathScanNSortDirectory.cpp
File metadata and controls
82 lines (74 loc) · 1.71 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
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
#include"pch.h"
#include "ScanNSortDirectory.h"
#if defined( WIN32 ) || defined(WIN64)
using namespace std;
#include <windows.h>
int str_compare(const void *arg1, const void *arg2)
{
return strcmp((*(std::string*)arg1).c_str(), (*(std::string*)arg2).c_str());
}
file_lists ScanNSortDirectory(const std::wstring &path, const std::wstring &extension)
{
WIN32_FIND_DATA wfd;
HANDLE hHandle;
wstring searchPath, searchFile;
file_lists vFilenames;
int nbFiles = 0;
searchPath = path + L"\\*" + extension;
hHandle = FindFirstFile(searchPath.c_str(), &wfd);
if (INVALID_HANDLE_VALUE == hHandle)
{
//fprintf(stderr, "ERROR(%s, %d): Cannot find (*.%s)files in directory %s\n",
// __FILE__, __LINE__, extension.c_str(), path.c_str());
//exit(0);
return vFilenames;
}
do
{
//. or ..
if (wfd.cFileName[0] == '.')
{
continue;
}
// if exists sub-directory
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
continue;
}
else//if file
{
searchFile = path + L"\\" + wfd.cFileName;
vFilenames.push_back(searchFile);
nbFiles++;
}
} while (FindNextFile(hHandle, &wfd));
//while (FindNextFile(hHandle, &wfd))
//{
//. or ..
// if (wfd.cFileName[0] == '.')
// {
// continue;
// }
// if exists sub-directory
// if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
// {
// continue;
// }
// else//if file
// {
/*searchFile = path + L"\\" + wfd.cFileName;
// vFilenames.push_back(searchFile);*/
// vFilenames.push_back(wfd.cFileName);
// nbFiles++;
// }
//}
FindClose(hHandle);
// sort the filenames
if (INVALID_HANDLE_VALUE == hHandle)
{
return vFilenames;
}
qsort((void *)&(vFilenames[0]), (size_t)nbFiles, sizeof(string), str_compare);
return vFilenames;
}
#endif