我用下面的超超超级简单的代码来列出一个猪病的所有文件(Windows 8.1,Visual Studio速成2013,C++)的一个简单的例子问题:C++ - 经与用FindFirstFile
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <limits>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <bitset>
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
using namespace std;
void get_file_list(string DATA_DIR)
{
HANDLE hFind;
WIN32_FIND_DATA data;
hFind = FindFirstFile(LPCWSTR(DATA_DIR.c_str()), &data);
if (hFind != INVALID_HANDLE_VALUE) {
do {
printf("%s\n", data.cFileName);
} while (FindNextFile(hFind, &data));
FindClose(hFind);
}
}
int main(int argc, char** argv)
{
string DATA_DIR = "D:\\drobpox\\Dropbox\\BinaryDescriptors\\LFW\\DATA\\*.*";
//string DATA_DIR = "c:\\Users\\GilLevi\\Downloads\\GraphsSURF\\GraphsSURF\\bark\\*.jpg";
string OUT_DIR = "D:\\drobpox\\Dropbox\\BinaryDescriptors\\LFW\\LATCH_TXT_FILES\\LATCH8";
get_file_list(DATA_DIR);
}
但是,我“hFind”总是等于“INVALID_HANDLE_VALUE”。我仔细检查了路径并尝试了各种不同的路径。
可能的原因是我正在运行64位应用程序并使用WIN32_FIND_DATA?
由于提前, 吉尔
那么当FindFirstFile失败时,GetLastError会返回什么? http://msdn.microsoft.com/en-us/library/windows/desktop/aa364418(v=vs.85).aspx – PaulMcKenzie 2014-10-20 21:56:14
你不能简化类型转换为LPCWSTR的字符串 – wimh 2014-10-20 21:56:52