void CFilesView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
::SetCurrentDirectory("C:\\");
search_file();
CScrollView::OnLButtonDown(nFlags, point);
}void CFilesView::search_file()
{
static CFile file("C:\\Documents and Settings\\Administrator\\桌面\\1.txt",CFile::modeWrite);
static CArchive arc(&file,CArchive::store);
WIN32_FIND_DATA data;
HANDLE handle=::FindFirstFile("*.*",&data);
if(INVALID_HANDLE_VALUE!=handle)
{
do{
if(data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{
CString string=data.cFileName;
CFile file;
file.Open(string,CFile::modeRead);
CString stringx=file.GetFilePath();
int base;
/*while(base=stringx.Find("\"),base!=-1)
stringx.Insert(base,"\");*/
if(string!="."&&string!=". .")
{
::SetCurrentDirectory(stringx);
arc.WriteString((char*)&stringx);
search_file();
::SetCurrentDirectory(". .");
}
}
}while(::FindNextFile(handle,&data));
::FindClose(handle);
}}
第一次:第二次:
解决方案 »
- ░▒▓█ VC里怎么用.net的PictureBox控件?
- 关于API的问题
- MFC如何將工程上的GBK轉換成BIG5格式的?
- VS2008编译没有生成pdb文件,导致dllmain的断点跟不进去。
- VC++的高手们进来看看 本人想做一个Vc++的小程序 请你们指点一下
- AfxBeginThread建立线程错误 ,怎么解决?
- 在一台主机上开两个socket与服务器(一个端口)连接可以吗?为何connect错误?
- 一般 vc 都用来开发什么程序呀?
- 如何在CToolBar上加帮助
- 如何写资源管理器类型程序
- TCP中如何判断,已建立一个socket后,对方断开了此连接
- recv返回值总是0,很郁闷呀···是否是服务器端的问题?
{
//排除"."与"..", 因为"."代表当前文件夹, ".."代表上一层文件夹
if (!lstrcmp(fileInfo.cFileName,".") || !lstrcmp(fileInfo.cFileName,".."))
{
//Do nothing for "." and ".." folders
}
else
{
...... //你的代码
}}
顺便问一下:
帮我分析下这个:
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(" "));
if(string!="."&&string!=". .")
{ //这里判断不等于上一层文件夹或当前文件夹什么意思,事实上判断是文件夹可以递归进去,不是就输出。
::SetCurrentDirectory(string);
search_file();
::SetCurrentDirectory(". .");
}
}
else
{
arc.WriteString(string);
arc.WriteString(CString(" "));
}
void FindAllFilesInPath(LPCTSTR strPath)
{
HANDLE hFile;
WIN32_FIND_DATA fndInfo;
char strPathName[MAX_PATH];
memset(strPathName, 0, MAX_PATH);
sprintf(strPathName, "%s\\*.*", strPath);
hFile = ::FindFirstFile(strPathName, &fndInfo);
do
{
if(hFile==INVALID_HANDLE_VALUE)
return;
else
{
if(fndInfo.cFileName[0]=='.')
continue;
char strNewName[MAX_PATH];
memset(strNewName, 0, MAX_PATH);
sprintf(strNewName, "%s\\%s", strPath, fndInfo.cFileName);
//如果是子目录,则递归搜索
if(fndInfo.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
FindAllFilesInPath(strNewName);
else//如果是文件
{
自己处理
}
}
}
while( ::FindNextFile(hFile, &fndInfo) );
::FindClose(hFile);
}
还是不对:你看我的》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);
}}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);
}