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
|
#include <windows.h>
#include <string>
#include <vector>
#include <stack>
#include <iostream>
using namespace std;
bool TraiterFichier(WIN32_FIND_DATA ffd, wstring path) {
double ngo = (ffd.nFileSizeHigh * MAXDWORD + ffd.nFileSizeLow) / ((double)(2 << 29));
if (ngo > 1) {
wcout << path << "\\" << ffd.cFileName << " " << ngo << "Go" << endl;
return true;
}
return false;
}
typedef bool(*FuncTraiterFichier)(WIN32_FIND_DATA ffd, wstring path);
void ListFiles(wstring path, wstring mask, vector<wstring>& files, FuncTraiterFichier funcTraiterFichier) {
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATA ffd;
wstring spec;
stack<wstring> directories;
directories.push(path);
files.clear();
while (!directories.empty()) {
path = directories.top();
spec = path + L"\\" + mask;
directories.pop();
hFind = FindFirstFile(spec.c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE) {
//return false;
continue;
}
do {
if (wcscmp(ffd.cFileName, L".") != 0 && wcscmp(ffd.cFileName, L"..") != 0) {
//wcout << path+ ffd.cFileName << "\n";
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
wstring tmp = path + L"\\" + ffd.cFileName;
//directories.push(tmp);
ListFiles(tmp, mask, files, funcTraiterFichier);
}
else {
if (funcTraiterFichier(ffd, path)) {
files.push_back(path + L"\\" + ffd.cFileName);
}
}
}
} while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
}
}
int main(int argc, char* argv[])
{
vector<wstring> files;
ListFiles(L"C:\\", L"*", files, TraiterFichier);
// lister ici files si on veut
return 0;
} |
Partager