如果你想要列出所有后缀为.cur的游标文件,那么你可以使用FindNextFile轻松做到,但是最好限于特定文件夹,因为你如果要全盘搜索,那效率是十分低的。
源码是开箱即用的:
#include <windows.h>
#include <iostream>
#include <tchar.h>
#pragma warning (disable: 4996)
TCHAR szDir1[MAX_PATH] = { 0 };
void retrievetxt(TCHAR* szDir)
{
WIN32_FIND_DATA ffd;
LARGE_INTEGER filesize;
_tcscat(szDir, _T("\\*"));
HANDLE hFind = FindFirstFile(szDir, &ffd);
// List all the files in the directory with some info about them.
do
{
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!_tcscmp(ffd.cFileName, _T(".")) || !_tcscmp(ffd.cFileName, _T("..")))
continue;
TCHAR szDircpy[MAX_PATH] = { 0 };
_tcscpy(szDircpy, szDir);
szDircpy[_tcslen(szDircpy) - 1] = _T('\0'); // remove "*" character from "xxx\\*"
_tcscat(szDircpy, ffd.cFileName); //add the subdirectory name into szDir
_tprintf(TEXT("Go into %s\\%s <DIR>\n"), szDircpy, ffd.cFileName);
retrievetxt(szDircpy);
}
else
{
int size = _tcslen(ffd.cFileName);
if (size > 4 && !_tcscmp(ffd.cFileName + size - _tcslen(_T(".cur")), _T(".cur")))
{
filesize.LowPart = ffd.nFileSizeLow;
filesize.HighPart = ffd.nFileSizeHigh;
_tprintf(TEXT("%s\\%s \n"), szDir1, ffd.cFileName);
}
}
} while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
}
int _tmain(int argc, TCHAR* argv[])
{
TCHAR szDir[MAX_PATH] = { 0 };
_tcscpy(szDir1, _T("C:\\Windows\\Cursors"));
_tcscpy(szDir, _T("C:\\Windows\\Cursors"));
_tprintf(TEXT("Go into %s <DIR>\n"), szDir);
retrievetxt(szDir);
getchar();
return 0;
}