Click to See Complete Forum and Search --> : what is wrong with the recursion


willi808
July 8th, 2003, 06:52 AM
//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);
}

}

AlionSolutions
July 10th, 2003, 04:44 AM
Hi,
ok this might be the ONLY posting you receive on this, and I think you should know why:

Do you think we have lot's of spare-time to figure out what your code does and what it doesn't. Ok your code looks not unfamilliar to me, but I DON'T WANT to dig through this.. sorry.

So please: In minimal tell us what your problem with this code is. It is not very kind to just throw a bunch of code to the crowd at codeguru and ask to find the problem.

we are not employed by you, and for that reason something like "thanks in advance" or "thanks for helping" might have been a good idea.

greetings

Juergen

Andreas Masur
July 10th, 2003, 05:01 AM
Well...I do not know exactly what the purpose of the function is, however, as a reference you might take a look at this FAQ (http://www.codeguru.com/forum/showthread.php?s=&threadid=231184) which I assume basically does what you want... :cool: