void EnumFolders()
{
WIN32_FIND_DATA fd;
HANDLE hFind = ::FindFirstFile("j:\\*.*", &fd); if ( hFind != INVALID_HANDLE_VALUE )
{
do {
CString strName = fd.cFileName;
MessageBox(NULL,strName,NULL,NULL); if ( fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )//是一个文件夹
{
//if ( strName != "." && strName != ".." )
{
MessageBox(NULL,"hahaha",NULL,NULL); if(0!=::SetCurrentDirectory(fd.cFileName))
{
MessageBox(NULL,"failed",NULL,NULL);
EnumFolders();
}
::SetCurrentDirectory("..");
}
}
}while (::FindNextFile(hFind, &fd)); ::FindClose(hFind);
}
}上面是一个遍历所有文件的代码(包括子目录中的文件)
这里的"j"是 u盘 ,在SetCurrentDirectory(fd.cFileName) 这句的时候出现了问题,就是说无法进入下一级的文件夹。
如果把“j”换成别的 盘 比如 C盘 程序就可以正常工作
请问这个是怎么回事??
{
WIN32_FIND_DATA fd;
HANDLE hFind = ::FindFirstFile("j:\\*.*", &fd); if ( hFind != INVALID_HANDLE_VALUE )
{
do {
CString strName = fd.cFileName;
MessageBox(NULL,strName,NULL,NULL); if ( fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )//是一个文件夹
{
//if ( strName != "." && strName != ".." )
{
MessageBox(NULL,"hahaha",NULL,NULL); if(0!=::SetCurrentDirectory(fd.cFileName))
{
MessageBox(NULL,"failed",NULL,NULL);
EnumFolders();
}
::SetCurrentDirectory("..");
}
}
}while (::FindNextFile(hFind, &fd)); ::FindClose(hFind);
}
}上面是一个遍历所有文件的代码(包括子目录中的文件)
这里的"j"是 u盘 ,在SetCurrentDirectory(fd.cFileName) 这句的时候出现了问题,就是说无法进入下一级的文件夹。
如果把“j”换成别的 盘 比如 C盘 程序就可以正常工作
请问这个是怎么回事??
DWORD FindFile(LPCTSTR Directory,LPCTSTR file_filter)//搜索文件
{
DWORD ret = ERROR_SUCCESS;
CString path = Directory; CString Find_path = Directory;
if(Find_path.Right(1) != '\\')
Find_path += "\\";
Find_path += file_filter; CFileFind finder;
BOOL res = finder.FindFile(Find_path);
while(ret == ERROR_SUCCESS && res) //找到此目录
{
res = finder.FindNextFile();
if(!finder.IsDirectory() && !finder.IsDots())//查找到文件
{
CString File_Name = finder.GetFilePath();
//处理
AfxMessageBox(File_Name);
}
else if(finder.IsDirectory() && !finder.IsDots())//查找到子目录
{
CString Next_path = finder.GetFilePath();
ret = FindFile(Next_path,file_filter);
}
}
finder.Close(); return(ret);
}
FindFile("j:\\","*.*");