Meola_Attack
New member
Hi all, guys, I need help with a program in c++. I need to explore a directory and all its sub-directories. My problem is the following one: when I search a file, the results contain files that don't exist, like "FOUND.00" , that compromise the good outcome... I tried to exclude them with this algorithm "if(strstr("FOUND.",buffer)!=0)..."but I don't obtain any result. Can you help me? I post here my algorithm:
void ExplorePC(char * directory, FILE * file)
{
WIN32_FIND_DATA data;
HANDLE hFind;
char slash[]="\\"; // directory + slash + point = directory\*.*
char point[]="*.*";
char string[]="\\*.*";
strcat(directory,string);
hFind = FindFirstFile(directory,&data);
if(hFind == INVALID_HANDLE_VALUE)
{
if(strstr(string,directory)==0)
{
int characters = strlen(directory)-strlen(string);
directory[characters]='{rss:Content}';
}
fprintf(file,"Impossible to explore the directory \"%s\".",directory);
return;
}
else
{
if(strstr(string,directory)==0)
{
int characters = strlen(directory)-strlen(string);
directory[characters]='{rss:Content}';
}
fprintf(file,"The files that have been found in \"%s\" are:\n",directory);
strcat(directory,slash);// Remove \\*.* from directory to printf the original directory in the file. Then add slash to directory that is ready to be pasted to the new files.
while(FindNextFile(hFind,&data)!=0)
{
char buffer[MAX_PATH];
strcpy(buffer,data.cFileName);
if(GetFileAttributes(data.cFileName) & FILE_ATTRIBUTE_DIRECTORY)
{
if(strstr("FOUND.",buffer)!=0)
{
fprintf(file,"%s\n",buffer);
strcat(directory,buffer);
cout<<directory<<"\n";
Sleep(700);
ExplorePC(directory,file);
}
}
}
}
return;
}
Ten points...Sorry for my bed English, I'm Italian
void ExplorePC(char * directory, FILE * file)
{
WIN32_FIND_DATA data;
HANDLE hFind;
char slash[]="\\"; // directory + slash + point = directory\*.*
char point[]="*.*";
char string[]="\\*.*";
strcat(directory,string);
hFind = FindFirstFile(directory,&data);
if(hFind == INVALID_HANDLE_VALUE)
{
if(strstr(string,directory)==0)
{
int characters = strlen(directory)-strlen(string);
directory[characters]='{rss:Content}';
}
fprintf(file,"Impossible to explore the directory \"%s\".",directory);
return;
}
else
{
if(strstr(string,directory)==0)
{
int characters = strlen(directory)-strlen(string);
directory[characters]='{rss:Content}';
}
fprintf(file,"The files that have been found in \"%s\" are:\n",directory);
strcat(directory,slash);// Remove \\*.* from directory to printf the original directory in the file. Then add slash to directory that is ready to be pasted to the new files.
while(FindNextFile(hFind,&data)!=0)
{
char buffer[MAX_PATH];
strcpy(buffer,data.cFileName);
if(GetFileAttributes(data.cFileName) & FILE_ATTRIBUTE_DIRECTORY)
{
if(strstr("FOUND.",buffer)!=0)
{
fprintf(file,"%s\n",buffer);
strcat(directory,buffer);
cout<<directory<<"\n";
Sleep(700);
ExplorePC(directory,file);
}
}
}
}
return;
}
Ten points...Sorry for my bed English, I'm Italian