1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
void DriveExplore(char* path,const char* chosenDir,fstream* theStream,bool listFiles)
{
WIN32_FIND_DATA findData;
HANDLE hSearch;
if(listFiles)
{
*theStream<<"<r>"<<endl;
*theStream<<chosenDir<<endl;
*theStream<<"<f>"<<endl;
}
strcat(path,"\\*.*");
hSearch=FindFirstFile(path,&findData);
if(hSearch!=INVALID_HANDLE_VALUE)
{
do
{
if(listFiles==false)
{
if(findData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
{
RemoveEndString(path,"\\*.*");
char slashs[2]="\\";
if(!StartsWith(findData.cFileName,"."))
{
chosenDir=findData.cFileName;
cout<<chosenDir<<endl;
strcat(slashs,chosenDir);
strcat(path,slashs);
//cout<<"Current path :"<<path<<endl;
DriveExplore(path,chosenDir,theStream,true);
}
else
{
break;
}
}
}
else //if(listFiles==true)
{
if(!(findData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
{
*theStream<<findData.cFileName<<endl;
}
}
}while(FindNextFile(hSearch,&findData));
}
if(listFiles==true)
{
*theStream<<"</f>"<<endl;
RemoveEndString(path,"\\*.*");
DriveExplore(path,chosenDir,theStream,false);
}
else if(listFiles==false);
{
*theStream<<"</r>"<<endl;
}
}
|