Ive tried asking this stuff before but unfortunatly i havent quite found a solution yet so i figured id post a bit of an update. Im using MFC to scan a LARGE network storage device, talking 3TB highly nested. I recently changed my scanning algorithm to this.
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);
cout<<path<<"\\"<<fileData.cFileName<<","<<acctName<<endl;
}
}
FindClose(searchHandle);
for (int i=0; i<dirs.size(); i++)
{
//cout<<"recursing"<<endl;
dirName = dirs;
scanPath(path+"\\"+dirName, fileData);
}
}
The algorithm is leaving the files marked as open. Two questions
1) Can i get summary file information (file name, size, write and access dates, owner) Without leaving the file open?
2) If not how can i close the file right after i get that information?
Thank you everyone
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);
cout<<path<<"\\"<<fileData.cFileName<<","<<acctName<<endl;
}
}
FindClose(searchHandle);
for (int i=0; i<dirs.size(); i++)
{
//cout<<"recursing"<<endl;
dirName = dirs;
scanPath(path+"\\"+dirName, fileData);
}
}
The algorithm is leaving the files marked as open. Two questions
1) Can i get summary file information (file name, size, write and access dates, owner) Without leaving the file open?
2) If not how can i close the file right after i get that information?
Thank you everyone