41 lines
848 B
C++
41 lines
848 B
C++
#include "PlatAPI.h"
|
|
#include <Windows.h>
|
|
#include <iostream>
|
|
using namespace std;
|
|
|
|
vector<FileInfo> ListDir(const std::string& dirName)
|
|
{
|
|
vector<FileInfo> vec;
|
|
WIN32_FIND_DATAA findData;
|
|
LARGE_INTEGER filesize;
|
|
string patternName = dirName + "\\*";
|
|
HANDLE hand = FindFirstFileA(patternName.c_str(), &findData);
|
|
if (hand == INVALID_HANDLE_VALUE)
|
|
{
|
|
cout << "Failed to ListDir: " << GetLastError() << endl;
|
|
return vec;
|
|
}
|
|
do
|
|
{
|
|
FileInfo f;
|
|
f.name = std::string(findData.cFileName);
|
|
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
{
|
|
f.type = 1;
|
|
f.size = 0;
|
|
}
|
|
else
|
|
{
|
|
f.type = 0;
|
|
filesize.LowPart = findData.nFileSizeLow;
|
|
filesize.HighPart = findData.nFileSizeHigh;
|
|
f.size = filesize.QuadPart;
|
|
}
|
|
vec.push_back(f);
|
|
|
|
} while (FindNextFileA(hand, &findData));
|
|
|
|
FindClose(hand);
|
|
return vec;
|
|
}
|