65,186
社区成员




#include <windows.h>
#include <tchar.h>
#include <cstdio>
#include <vector>
#include <string>
#define LEN 1024
using namespace std;
#ifdef _UNICODE
typedef wstring TSTRING;
#else
typedef string TSTRING;
#endif
vector<TSTRING> DirectoryList(LPCTSTR PATH)
{
vector<TSTRING> address;
WIN32_FIND_DATA FindData;
HANDLE hError;
int FileCount = 0;
TCHAR FilePathName[LEN];
// 构造路径
TCHAR FullPathName[LEN];
_tcscpy(FilePathName, PATH);
_tcscpy(FilePathName, _T("\\*.*"));
hError = FindFirstFile(FilePathName, &FindData);
if (hError == INVALID_HANDLE_VALUE)
{
printf("搜索失败!");
}
//char f[200]; //ggggggaaaaiiiii
//f = (char*)malloc(40 * sizeof(char));
while (::FindNextFile(hError, &FindData))
{
// 过虑.和..
if (_tcscmp(FindData.cFileName, _T(".")) == 0
|| _tcscmp(FindData.cFileName, _T("..")) == 0)
{
continue;
//return 0;
}
// 构造完整路径
wsprintf(FullPathName, _T("%s\\%s"), PATH, FindData.cFileName);
FileCount++;
// 输出本级的文件
printf("\n%d %s \n", FileCount, FullPathName);
/*
if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
printf("<Dir>");
DirectoryList(FullPathName);
}
*/
address.push_back(FullPathName);
}
//cout << address.size() << endl;
return address;
}