void CFilesView::search_file(char strPath[])
{
static CFile file("C:\\Documents and Settings\\Administrator\\桌面\\1.txt",CFile::modeWrite);
static CArchive arc(&file,CArchive::store);
static char strNewName[100],strNewName1[100];
WIN32_FIND_DATA data;
sprintf(strNewName1, "%s\\ *.*", strPath);
HANDLE handle=::FindFirstFile(strNewName1,&data);
if(INVALID_HANDLE_VALUE!=handle)
{
do{
CString string=data.cFileName;
if(data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{
CFile file;
file.Open(string,CFile::modeRead);
CString stringx=file.GetFilePath();
int base;
arc.WriteString(string);
arc.WriteString(CString(" "));
sprintf(strNewName, "%s\\%s", strPath, data.cFileName);
if(string!="."&&string!=". .")
{
//::SetCurrentDirectory(string);
search_file(strNewName);
//::SetCurrentDirectory(". .");
}
}
else
{
arc.WriteString(string);
arc.WriteString(CString(" "));
}
}while(::FindNextFile(handle,&data));
::FindClose(handle);
}}
C/C++ code
void CFilesView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//::SetCurrentDirectory("G:\\xx\\");
search_file("G:\\\\xx\\\\");
CScrollView::OnLButtonDown(nFlags, point);
}遍历失败,,
解决方案 »
- 请问word2007插件开发问题
- 我想添加浏览器控件 可是VC6添加进工程组件和控件里面找不到Registered ActiveX Controls文件夹
- 网络编程 netbios 遇到的一个对你们来说很简单的问题···跪地请求帮助···50分跪地磕头请求您的帮助···
- 有谁写过64为程序
- 在VC中如何实现关闭窗口但不退出整个主程序
- 软件的低耦合、高内聚怎么理解?
- 如何捕获_RecordsetPtr 添加一条记录时的错误信息
- 在线等, 关于CComboBox的问题
- VC6.0编译不能生成obj文件
- 请教:为什么设定完字体之后,设不回原来的字体了呢?
- 求导致sendto执行的时间过长的原因
- UAC的超级难题,混分的别进来。200分。
你用了sprintf(strNewName1, "%s\\ *.*", strPath);因为你这里加了\\
调用时改成search_file("G:\\xx");
给你个 别人写的遍历程序
struct _finddata_t c_file={0};
char szDir[256] = {0};
strcpy(szDir, pdir);
if(szDir[strlen(szDir)-1] != '\\')
strcat(szDir,"\\");
strcat(szDir,"*.*"); long hFile = _findfirst(szDir,&c_file);
if(hFile == -1)
return;
do
{
if(strcmp(c_file.name,".")==0||strcmp(c_file.name,"..")==0)
continue;
if(c_file.attrib & _A_SUBDIR)
{
char szSub[256] = {0};
strcpy(szSub, pdir);
if(szSub[strlen(szSub)-1] != '\\')
strcat(szSub,"\\");
strcat(szSub,c_file.name);
travedir(szSub);
GetDlgItem(IDC_STR_REMIND)->SetWindowText(szSub);
}
else
{
if(strcmp(c_file.name,"Tc.dll")==0||strcmp(c_file.name,"tc.dll")==0||strcmp(c_file.name,"TC.dll")==0)
travedest(pdir);//找到后的操作
}
}while(_findnext(hFile, &c_file)== 0);
_findclose(hFile);