LuaYard/PlatAPI.cpp

43 lines
900 B
C++
Raw Permalink Normal View History

2019-08-07 14:15:01 +08:00
#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);
2019-08-10 21:35:37 +08:00
if (f.name == "." || f.name == "..")
continue;
2019-08-07 14:15:01 +08:00
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;
}