window api 查找指定路径下的类型文件(无递归)

#include <Windows.h>
#include <atlstr.h>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
CString dir;
dir="d:\\*.txt";
LPCTSTR bufDir;
bufDir=(LPCTSTR)dir;
wcout << "Target file is " << bufDir << endl;
hFind = FindFirstFile(bufDir, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) 
{
wcout << "Invalid File Handle. GetLastError reports " << GetLastError () << endl;
return (0);
} 
else 
{
wcout << "The first file found is " << FindFileData.cFileName << endl;
FindClose(hFind);
system("pause");
return (1);
}
}


你可能感兴趣的:(window api 查找指定路径下的类型文件(无递归))