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

来源:互联网 发布:美元加息的影响 知乎 编辑:程序博客网 时间:2024/06/11 05:48
#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);}}