//search all subdirectories (recursion)
void SearchAllDir(char *argv1, char *argv2)
{
struct find_t sdir; //file attribute in a struct
char buffer[500]; //buffer of path (drive and directory)
char buffer2[500]; //buffer of path (drive and directory)
int result; //result of subdirectories
//arrays to NULL
*buffer = NULL;
*buffer2 = NULL;
//drive letter to buffer
strcpy(buffer,argv1);
//add ':\'
strcat(buffer,":\\"
;
//add path of directories
strcat(buffer,argv2);
// printf("%s\n",&buffer);
// printf("%s\n",&buffer2);
//buffer to buffer2 for dates
strcpy(buffer2, buffer);
//next level of subdirectories
strcat(buffer,"\\*.*"
;
//search first subdirectory in the next level
result = _dos_findfirst( buffer, _A_SUBDIR, &sdir);
//_dos_finfirst return '0' if true
while(result == 0)
{
//is there any subdirectory
if( sdir.attrib & _A_SUBDIR )
{
//no subdirectories which begins with '.' like '.' and '..'
if(sdir.name[0] != '.')
{
*buffer = NULL; //empty buffer
strcpy(buffer,argv2); //add complete path to buffer
strcat(buffer,"\\"
; //add '\'
strcat(buffer,sdir.name); //add name of subdirectory
// printf("%s\n",&buffer);
//recursion (with new path)
SearchAllDir(argv1, buffer);
//read actual date und creation dates of subdirectories
if(SearchDates(argv1,buffer) == 1)
{
Wait();
//delete files in directory
DelFiles(argv1, buffer);
//delete directories
DelDir(argv1,buffer);
}
}
}
//if there is no lower level go to next directory
result = _dos_findnext(&sdir);
}
}
void SearchAllDir(char *argv1, char *argv2)
{
struct find_t sdir; //file attribute in a struct
char buffer[500]; //buffer of path (drive and directory)
char buffer2[500]; //buffer of path (drive and directory)
int result; //result of subdirectories
//arrays to NULL
*buffer = NULL;
*buffer2 = NULL;
//drive letter to buffer
strcpy(buffer,argv1);
//add ':\'
strcat(buffer,":\\"
//add path of directories
strcat(buffer,argv2);
// printf("%s\n",&buffer);
// printf("%s\n",&buffer2);
//buffer to buffer2 for dates
strcpy(buffer2, buffer);
//next level of subdirectories
strcat(buffer,"\\*.*"
//search first subdirectory in the next level
result = _dos_findfirst( buffer, _A_SUBDIR, &sdir);
//_dos_finfirst return '0' if true
while(result == 0)
{
//is there any subdirectory
if( sdir.attrib & _A_SUBDIR )
{
//no subdirectories which begins with '.' like '.' and '..'
if(sdir.name[0] != '.')
{
*buffer = NULL; //empty buffer
strcpy(buffer,argv2); //add complete path to buffer
strcat(buffer,"\\"
strcat(buffer,sdir.name); //add name of subdirectory
// printf("%s\n",&buffer);
//recursion (with new path)
SearchAllDir(argv1, buffer);
//read actual date und creation dates of subdirectories
if(SearchDates(argv1,buffer) == 1)
{
Wait();
//delete files in directory
DelFiles(argv1, buffer);
//delete directories
DelDir(argv1,buffer);
}
}
}
//if there is no lower level go to next directory
result = _dos_findnext(&sdir);
}
}