16,472
社区成员
发帖
与我相关
我的任务
分享
//调用方式:在一个按钮控件中调用,在第二次按下按钮后,FileNames大小为0,这是为啥?
//路径什么都没有改!
vector<string> FileNames;//本次需要解析的文件的列表。
MyFindFile(HfilePath.c_str(), "txt", FileNames);
…………………………………………
bool CSaveLogFile::MyFindFile(const char *FileDir, char *FileTpye, vector<string> &list)
{
//_A_NORMAL 0x00 /* Normal file - No read/write restrictions */
//_A_RDONLY 0x01 /* Read only file */
//_A_HIDDEN 0x02 /* Hidden file */
//_A_SYSTEM 0x04 /* System file */
//_A_SUBDIR 0x10 /* Subdirectory */
//_A_ARCH 0x20 /* Archive file */
string dir_t = FileDir;
dir_t += "\\";
dir_t += "*.";
dir_t += FileTpye;
struct _finddata_t c_file;
intptr_t hFile;
if( (hFile = _findfirst(dir_t.c_str(), &c_file )) == -1L )//第二次调用时这里hFile == -1,我没改过路径,第一次能找到文件,第二次再找就找不到了。
{
//printf( "未找到设置的路径,文件夹不存在!\n" );
//return false;
_findclose( hFile );
}
else
{
do {
if ( c_file.attrib & _A_SUBDIR )//如果当前是文件夹
{
if (strcmp(c_file.name,".") == 0 || strcmp(c_file.name,"..") == 0 )
{
continue;
}
string dir_t2 = FileDir;
dir_t2 += "\\";
dir_t2 += c_file.name;
MyFindFile(dir_t2.c_str(), FileTpye, list);
}
else
{
//printf( " %s\n",c_file.name);
string str = FileDir;
str += c_file.name;
list.push_back(str);
}
} while( _findnext( hFile, &c_file ) == 0 );
_findclose( hFile );
}
return true;
}
bool CSaveLogFile::MyFindFile(const char *FileDir, char *FileTpye, vector<string> &list)
{
//_A_NORMAL 0x00 /* Normal file - No read/write restrictions */
//_A_RDONLY 0x01 /* Read only file */
//_A_HIDDEN 0x02 /* Hidden file */
//_A_SYSTEM 0x04 /* System file */
//_A_SUBDIR 0x10 /* Subdirectory */
//_A_ARCH 0x20 /* Archive file */
string dir_t = FileDir;
//dir_t += "\\";
dir_t += "*.";
dir_t += FileTpye;
struct _finddata_t c_file = {0};
intptr_t hFile;
hFile = _findfirst(dir_t.c_str(), &c_file );
if(hFile == -1L )
{
//printf( "未找到设置的路径,文件夹不存在!\n" );
int clerror = _findclose( hFile );
return false;
}
else
{
do {
if ( c_file.attrib & _A_SUBDIR )//如果当前是文件夹
{
if (strcmp(c_file.name,".") == 0 || strcmp(c_file.name,"..") == 0 )
{
continue;
}
string dir_t2 = FileDir;
dir_t2 += "\\";
dir_t2 += c_file.name;
MyFindFile(dir_t2.c_str(), FileTpye, list);
}
else
{
//printf( " %s\n",c_file.name);
string str = FileDir;
str += c_file.name;
list.push_back(str);
}
} while( _findnext( hFile, &c_file ) == 0 );
}
int clerror = _findclose( hFile );
return true;
}
_findclose( hFile );
返回的是0,貌似正常啊。