【MFC】 谁来救救我。

wojiushi3344 2010-08-23 01:06:10
大家好,我现在遇到个难题,希望能帮帮我。上次发的看不见图片,这次从新发、
...全文
108 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wojiushi3344 2010-08-23
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 gameslq 的回复:]
C/C++ code

if(finder.IsDirectory())
{
IsHaveTxt(finder.GetFilePath();
}
改为:
if(finder.IsDirectory())
{
if(IsHaveTxt(finder.GetFilePath())
{
//不用再找了,关闭
finder.Close();
ret……
[/Quote]

你不觉得你的代码有问题吗?你这个只是判断它是不是目录,是就返回TRUE,根本就没有判断里面有没有TXT文件。
gameslq 2010-08-23
  • 打赏
  • 举报
回复

if(finder.IsDirectory())
{
IsHaveTxt(finder.GetFilePath();
}
改为:
if(finder.IsDirectory())
{
if(IsHaveTxt(finder.GetFilePath())
{
//不用再找了,关闭
finder.Close();
return true;
}
}
xxd_qd 2010-08-23
  • 打赏
  • 举报
回复
请看1楼的代码
wojiushi3344 2010-08-23
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 hurryboylqs 的回复:]
C/C++ code

bool IsHaveTxt(CString strFolder)
{
CFileFind finder;

// build a string with wildcards
CString strWildcard(strFolder);
strWildcard += _T("\\*.*");

// start ……
[/Quote]

我看了哈你写得程序,你不觉得你写的和我写的是一个道理吗?还不是没对返回值进行处理。
wojiushi3344 2010-08-23
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 hurryboylqs 的回复:]
C/C++ code

bool IsHaveTxt(CString strFolder)
{
CFileFind finder;

// build a string with wildcards
CString strWildcard(strFolder);
strWildcard += _T("\\*.*");

// start ……
[/Quote]

我先回去试一下,看得行不?
wojiushi3344 2010-08-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 djj315 的回复:]
这就是一个递归的问题,你对递归的返回值没有做处理。。。
[/Quote]

那该怎么处理呀。。。
hurryboylqs 2010-08-23
  • 打赏
  • 举报
回复

bool IsHaveTxt(CString strFolder)
{
CFileFind finder;

// build a string with wildcards
CString strWildcard(strFolder);
strWildcard += _T("\\*.*");

// start working for files
BOOL bWorking = finder.FindFile(strWildcard);
bool bRet=false;
while (bWorking)
{
bWorking = finder.FindNextFile();

// skip . and .. files; otherwise, we'd
// recur infinitely!

if (finder.IsDots())
continue;

// if it's a directory, recursively search it
if (finder.IsDirectory())
{
bRet= IsHaveTxt(finder.GetFilePath());
}
else
{
CString strTemp = finder.GetFileName();
int nPos = strTemp.ReverseFind('.');
strTemp = strTemp.Mid(nPos+1);
strTemp.MakeUpper();
if (strTemp==_T("TXT"))
{
finder.Close();
return true;
}
}
}

finder.Close();
return bRet;
}
hurryboylqs 2010-08-23
  • 打赏
  • 举报
回复
因为函数是被递归调用的
Simao 2010-08-23
  • 打赏
  • 举报
回复
这就是一个递归的问题,你对递归的返回值没有做处理。。。
stonewater 2010-08-23
  • 打赏
  • 举报
回复
if(finder.IsDirectory())
{
IsHaveTxt(finder.GetFilePath();
}
改为以下试试
if(finder.IsDirectory())
{
if(IsHaveTxt(finder.GetFilePath())
return true;
}

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧