Windows 下遍历指定文件夹找不到文件夹 - C++ Builder / Windows SDK/API
#include<windows.h>
#include<stdio.h>
BOOL ShowFileInDirectory(LPCSTR lpPathName);
BOOL ShowFileInDirectory(LPCWSTR lpPathName)
{
HANDLE hFile;
WIN32_FIND_DATA FileData;
TCHAR cPath[256];
lstrcpy(cPath, lpPathName);
lstrcat(cPath, "\\*");
hFile = FindFirstFile(lpPathName, &FileData);
if(hFile == INVALID_HANDLE_VALUE)
{
printf("error:%d\n",GetLastError());
return FALSE;
}
else
{
do
{
if(lstrcmp(FileData.cFileName, TEXT(".")) == 0 ||
lstrcmp(FileData.cFileName, TEXT("..")) == 0)
{
continue;
}
printf("%s\t\t",FileData.cFileName);
if(FileData.dwFileAttributes&FILE_ATTRIBUTE_ENCRYPTED)
{
printf("<encode>");
}
if(FileData.dwFileAttributes&FILE_ATTRIBUTE_HIDDEN)
{
printf("<hidden>");
}
if(FileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{
printf("<DIR>");
}
printf("\n");
}while(FindNextFile(hFile,&FileData));
}
return TRUE;
}
void main()
{
TCHAR lpBuffer[256];
scanf("%s",lpBuffer);
ShowFileInDirectory(lpBuffer);
}
[解决办法]
这里面有你想要的
http://topic.csdn.net/u/20080918/10/0468393a-e32e-4521-820c-3ce68bed991b.html?93110