您的位置:首页 > 其它

遍历当前目录下所有的.h文件,并将其路径保存到文件中

2013-01-06 22:32 369 查看
本文源程序vs2008实现 免积分下载地址: http://download.csdn.net/detail/moonshine99/4967281
void CFindAllFilesInDirDlg::OnBnClickedOk()

{

CString strCurrentPath;

GetModuleFileName(AfxGetInstanceHandle(),strCurrentPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);

int iPos = strCurrentPath.ReverseFind('\\');

strCurrentPath = strCurrentPath.Left(iPos);

CFile file;

file.Open(L"h.txt",CFile::modeCreate | CFile::modeWrite);

Recurse(file, strCurrentPath);

file.Close();

CString strPath("D:");

}

void CFindAllFilesInDirDlg::Recurse(CFile &file, LPCTSTR pstr)

{

CFileFind finder;

CString strWildcard(pstr);

strWildcard += _T("\\*.*");

BOOL bWorking = finder.FindFile(strWildcard);

while(bWorking)

{

bWorking=finder.FindNextFile();

CString temp=finder.GetFilePath();

if (finder.IsDots())

continue;

if(finder.IsDirectory())

{

CString str = finder.GetFilePath();

Recurse(file,str);

}

if(temp.Right(2) == ".h")

{

temp += L"\r\n";

file.Write(temp,temp.GetLength()*sizeof(TCHAR));

}

}

finder.Close();

}

本文源程序vs2008实现 免积分下载地址: http://download.csdn.net/detail/moonshine99/4967281
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: