不显示删除回复显示所有回复显示星级回复显示得分回复 如何用FindFirstFile遍历Documents and setting目录

来源:百度知道 编辑:UC知道 时间:2024/05/30 00:37:29
我想要遍历一下Documents and setting下所有的子目录,但现在我只能得到.;
不怎么会C++,麻烦大家帮忙看一下.
当前Documents and setting有一些隐藏文件,也不是知道是不是和这个有关系.
下面是源程序的片断,

HANDLE hFile;
WIN32_FIND_DATA fd;

LP lpHomeDir = TEXT("C:\\Documents and Settings\\*"); //这个目录名用转义对吗?
hFile = FindFirstFile(lpHomeDir,&fd);
if(hFile == INVALID_HANDLE_VALUE){
//返回错误代码
char errorString[20];
DWORD errorCode = GetLastError();
sprintf(errorString,"%d",errorCode);
return _com_util::ConvertStringToBSTR(errorString);
}

TCHAR cFileNames[1000];
ZeroMemory(cFileNames, sizeof(TCHAR) * 1000);

//文件名
lstrcat(cFileNames, fd.cFileName);
lstrcat(cFileNames, TEXT("\n"));

while(FindNextFile(hFile, &fd)){
lstrcat(cFileNames, fd.cFileName);
lstrcat(cFileNames, TEXT("\n"));
}

return cFileNames;

我刚才试了下,你的程序没有问题,你返回的是一个字符串的指针

你取得的数据应该是这样的:.\n..\nDefault User\n等等

如果只看一位的话肯定是‘.’了 

我用的程序测试的结果是,在图上,返回的时候AfxMessageBox(cFileNames);

HANDLE hFile;
WIN32_FIND_DATA fd;

LP lpHomeDir = TEXT("C:\\Documents and Settings\\*.*");
hFile = FindFirstFile(lpHomeDir,&fd);
if(hFile == INVALID_HANDLE_VALUE)
{
char errorString[20];
DWORD errorCode = Get