_findfirst为什么会返回-1
第一步我在调用文件对话框保存完文件后,代码如下:
我调用了文件对话框的代码
char buf[MAX_PATH] = {};
HWND hwnd = GetActiveWindow();
OPENFILENAME ofn = {};
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = buf;
ofn.nMaxFile = MAX_PATH;
if (IDOK == GetSaveFileName(&ofn))
{
wr.Create();
char tmap[_MAP_S];
for (int i = 0;i < _MAP_S; ++i)
{
int cx = i % _MAP_W;
int cy = i / _MAP_W;
char* q = ag.GetGrid(cx, cy);
tmap[cx + cy * _MAP_W] = *q;
}
wr.WriteString(tmap);
wr.Write(buf);
}
第二步点击列表框得到一条选中的文件名,再遍历一个目录下的所有文件得到这个文件。
int CGameScene::insertDirectory( const char* dn,std::vector<std::string>* list )
{
int r = 0;
std::string s1 = dn;
s1 += "\\*.*";
_finddata_t fd;
intptr_t fr = _findfirst(s1.c_str(), &fd);
if (-1 != fr)
{
do
{
//子目录
if (fd.attrib & _A_SUBDIR)
{
if (strcmp(fd.name, ".") != 0 && strcmp(fd.name, "..") != 0)
{
std::string s2 = dn;
s2 += "\\";
s2 += fd.name;
r += insertDirectory(s2.c_str(),list);
}
}
//文件
else
{
//检查是否为位图文件
char* p = strrchr(fd.name, '.');
if (p)
{
//得到后缀名
std::string s3 = p + 1;
//将所有的字符归于小写
for (unsigned int i = 0; i < s3.length(); ++i)
{
if (s3[i] >= 'A' && s3[i] <= 'Z')
s3[i] += ('a' - 'A');
}
//确实为位图文件
if (strcmp(s3.c_str(), "map") == 0)
{
std::string s4 = "";
//s4 += "\\";
s4 += fd.name;
r += 1;
list->push_back(s4);
}
}
}
} while (0 == _findnext(fr, &fd));
_findclose(fr);
}
return r;
}
intptr_t fr = _findfirst(s1.c_str(), &fd);就返回-1了,我不调用第一段的代码,单独调用第二段的代码就能返回非-1.请问各位大神怎么解决这问题。
相关推荐
c语言文件夹_findfirst()函数介绍
c语言文件夹_findfirst()函数介绍
C++利用 _findfirst与_findnext查找文件的方法
C++ 文件查找 在C++中我们要如何查找文件呢?我们需要一个结构体和几个大家可能不太熟悉的函数。这些函数和结构体在的头文件中,结构体为struct _finddata_t ,函数为_findfirst、_findnext和_fineclose。具体如何使用,下面来一起看看吧 _findfirst与_findnext查找文件 一、这两个函数均在io.h里面。 二、首先了解一下一个文件结构体: struct _finddata_t { unsigned attrib; time_t time_create; time_t time_access; time_t time_wr
Java Stream findFirst()详解[源码]
本文详细介绍了Java 8中Stream API的findFirst()方法,该方法用于返回流中的第一个元素作为Optional对象。如果流为空,则返回空的Optional;如果流无序,则可能返回任意元素;如果元素为null,则会抛出NullPointerException。文章通过多个示例展示了findFirst()的使用场景,包括基本类型流(IntStream、LongStream、DoubleStream)和并行流的应用,并特别指出了处理null值时的注意事项。此外,还解释了findFirst()作为短路终端操作的特性,即它可以在无限流中提前终止操作。
Realm_find_first:在 Realm 中使用 findFirst 查找错误的示例项目
领域先找 在 Realm 中使用 findFirst 查找错误的示例项目。 有关更多信息,请参阅
用WIN32_FIND_DATA+FindFirst读出文件
VC_SDK下用WIN32_FIND_DATA+FindFirst读出文件


