Hey all,
Im trying to recursively scan a file system obtaining information like file name, file size, access dates, etc. Im using windows api to do this using the FindFirstFile and FindNextFile functions to scan through directories.
These functions open a file handle which acts like an open file to the operating system. When i scan a large number of files i end up with a ton of open files and i dont close the handle until the directory is done so in some cases i run out of available open files (windows has a limit) Additionally no one can use the files i have scanned until i close them.
Does anyone know a way i can recursively scan an directory without opening the files?
Thanks.
p.s. my old code is below
Im trying to recursively scan a file system obtaining information like file name, file size, access dates, etc. Im using windows api to do this using the FindFirstFile and FindNextFile functions to scan through directories.
These functions open a file handle which acts like an open file to the operating system. When i scan a large number of files i end up with a ton of open files and i dont close the handle until the directory is done so in some cases i run out of available open files (windows has a limit) Additionally no one can use the files i have scanned until i close them.
Does anyone know a way i can recursively scan an directory without opening the files?
Thanks.
p.s. my old code is below
Code:
void scanPath(string path, WIN32_FIND_DATA &fileData)
{
vector <string> dirs;
string dirName;
string pathToScan;
HANDLE searchHandle;
string acctName;
string filename;
pathToScan = combinePath(path, "*");
//cout<<path<<endl;
searchHandle = FindFirstFile(pathToScan.c_str(), &fileData);
//cout<<"after search handle"<<endl;
while (FindNextFile(searchHandle, &fileData))
{
if (strcmpi (fileData.cFileName, ".") != 0 &&
strcmpi (fileData.cFileName, "..") != 0)
{
//cout<<"In While"<<endl;
if (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
dirs.push_back(fileData.cFileName);
}
filename = combinePath(path, fileData.cFileName);
//getOwnerName(filename.c_str(), acctName);
GetOwner(filename.c_str(), acctName);
cout<<path<<"\\"<<fileData.cFileName<<","<<acctName<<endl;
}
}
FindClose(searchHandle);
for (int i=0; i<dirs.size(); i++)
{
// cout<<"recursing"<<endl;
dirName = dirs[i];
scanPath(path+"\\"+dirName, fileData);
}
}