001
07.10.2003, 19:24 Uhr
Uwe
C/C++ Master (Administrator)
|
Hallo,
C++: |
#include <string> #include <vector> #include <iostream>
#include <conio.h>
int SearchDirectory(std::vector<std::string> &refvecDirectories, const std::string &refcstrRootDirectory, bool bSearchSubdirectories = true) { std::string strPath; std::string strPattern; HANDLE hFile; WIN32_FIND_DATA FileInformation;
strPattern = refcstrRootDirectory + "\\*.*";
hFile = ::FindFirstFile(strPattern.c_str(), &FileInformation); if(hFile != INVALID_HANDLE_VALUE){ do{ if(FileInformation.cFileName[0] != '.'){ strPath.erase(); strPath = refcstrRootDirectory + "\\ " + FileInformation.cFileName;
if(FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){ refvecDirectories.push_back(strPath);
if(bSearchSubdirectories){ int iRC = SearchDirectory(refvecFiles, strPath, bSearchSubdirectories); if(iRC) return iRC; } } } } while(::FindNextFile(hFile, &FileInformation) == TRUE); ::FindClose(hFile);
DWORD dwError = ::GetLastError(); if(dwError != ERROR_NO_MORE_FILES) return dwError; }
return 0; }
int main() { std::vector<std::string> vecDirectories; int iRC = SearchDirectory(vecDirectories, "c:"); if(iRC){ std::cout << "Error " << iRC << std::endl; return -1; }
for(std::vector<std::string>::iterator iter = vecDirectories.begin(); iter != vecDirectories.end(); ++iter) std::cout << *iter << std::endl; _getch();
return 0; }
|
--edit-- Klammerungsfehler beseitigt -- "Es ist schwierig, ein Programm wirklich idiotensicher zu machen, weil Idioten so genial sind."
Bis dann... Uwe Dieser Post wurde am 07.10.2003 um 20:00 Uhr von FloSoft editiert. |