暴简单的console程序怎么就不行呢?——怎么列出某一目录下的所有文件名?
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
CString strDir;
CFileFind Finder;
BOOL bWorking;
CString strFixedFile = "*.*";
CString strFileName;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
printf((LPCSTR)"Please enter the directory:\n");
scanf("%s", strDir);
strDir += _T('\\');
strDir += strFixedFile;
printf((LPCSTR)strDir);
bWorking = Finder.FindFile(strDir);
while( bWorking )
{
bWorking = Finder.FindNextFile();
if ( Finder.IsDots() )
continue;
strFileName = Finder.GetFileName();
printf((LPCSTR)strFileName);
}
}
return nRetCode;
}
一个如此简单的打印某一目录下所有文件名的程序怎么就没有正确结果?
不管怎么给path,得到的总是d:盘下的一级子目录名,faint!