1. Si nella prima guarda sto link
2. Si nella seconda guarda sto esempio
int CTools::SearchFiles(std::set<std::wstring> &refvecFiles,
const std::wstring &refcstrRootDirectory,
std::wstring &refcstrExtension,
bool bSearchSubdirectories,
bool fullPath)
{
std::wstring strFilePath; // Filepath
std::wstring strPattern; // Pattern
std::wstring strExtension; // Extension
HANDLE hFile; // Handle to file
WIN32_FIND_DATA FileInformation; // File information
strPattern = refcstrRootDirectory + _T("\\*.*");
std::transform(refcstrExtension.begin(), refcstrExtension.end(), refcstrExtension.begin(), tolower);
std::transform(strPattern.begin(), strPattern.end(), strPattern.begin(), tolower);
hFile = ::FindFirstFile(strPattern.c_str(), &FileInformation);
if(hFile != INVALID_HANDLE_VALUE)
{
do
{
if(FileInformation.cFileName[0] != '.')
{
strFilePath.erase();
strFilePath = FileInformation.cFileName;
if(FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(bSearchSubdirectories)
{
// Search subdirectory
std::transform(strExtension.begin(), strExtension.end(), strExtension.begin(), tolower);
std::transform(strFilePath.begin(), strFilePath.end(), strFilePath.begin(), tolower);
int iRC = SearchFiles(refvecFiles,
refcstrRootDirectory + _T("\\") + strFilePath,
refcstrExtension,
bSearchSubdirectories,fullPath);
if(iRC)
return iRC;
}
}
else
{
// Check extension
strExtension = FileInformation.cFileName;
strExtension = strExtension.substr(strExtension.rfind(_T(".")) + 1);
std::transform(strExtension.begin(), strExtension.end(), strExtension.begin(), tolower);
std::transform(strFilePath.begin(), strFilePath.end(), strFilePath.begin(), tolower);
if(strExtension == refcstrExtension)
{
// Save filename
std::set<std::wstring>::iterator it;
if(fullPath)
{
it = refvecFiles.find(refcstrRootDirectory + _T("\\") + strFilePath);
if(it == refvecFiles.end())
{
refvecFiles.insert(refcstrRootDirectory + _T("\\") + strFilePath);
}
}
else
{
it = refvecFiles.find(strFilePath);
if(it == refvecFiles.end())
{
refvecFiles.insert(strFilePath);
}
}
}
}
}
}while(::FindNextFile(hFile, &FileInformation) == TRUE);
// Close handle
::FindClose(hFile);
DWORD dwError = ::GetLastError();
if(dwError != ERROR_NO_MORE_FILES)
return dwError;
}
return 0;
}
C'è molto lavoro da fare cmq.