can you see a better way to do this? constructive critisism wanted - Programmer

This is a discussion on can you see a better way to do this? constructive critisism wanted - Programmer ; Hello, I doubt that you have read an earlier post of mine regarding a method for recursively searching for files. I had some trouble with the function and, with the help of the internet and this news group, was able ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: can you see a better way to do this? constructive critisism wanted

  1. can you see a better way to do this? constructive critisism wanted

    Hello,

    I doubt that you have read an earlier post of mine regarding a method
    for recursively searching for files. I had some trouble with the
    function and, with the help of the internet and this news group, was
    able to devise a function for my purposes. What i have is a function
    that will recursively search for a file given a starting directory and
    a file to search for. It has default values for both the directory and
    the file name. What I am hoping is that you, the people of this news
    group, will take a look at it and give me any constructive critisism on
    how it may be implemented more efficiently, if possible. The idea of
    the function is to search the current directory of files that match the
    file being searched for and then continued down to the next
    sub-directory and do the same thing. The idea is to get the files out
    of the directory before moving to a sub-directory. Right now I don't
    have a variable in the function to kill it if the file is found as I am
    not yet sure how I am going to incorporate the function into my
    program. Just take a look and let me know if you see a better way to do
    it.

    // recursive function that searches the directory tree
    // starting at a designated starting directory. If not
    // starting directory is given then the search begins
    // at the root
    void
    RecursiveFileSearch( char *FindFile = "*.*", char *StartDir = "*.*")
    {
    int i = -1;//, j = -1;
    char dirL[255], tmpL[255], fileL[255];//char buffers for holding names
    //clearing out the memory of the char buffers to make sure no junk is
    accidently loaded
    ZeroMemory(dirL,sizeof(dirL));
    ZeroMemory(fileL,sizeof(fileL));
    ZeroMemory(tmpL,sizeof(tmpL));

    //checks to see if the search directory is the default value
    //if it is not, then \*.* is added to the end of the directory
    //name, otherwise the values are copied over as is
    if(strcmp(StartDir,"*.*"))
    {
    sprintf(dirL,"%s\\*.*",StartDir);
    sprintf(fileL,"%s\\%s",StartDir,FindFile);
    }
    else
    {
    sprintf(dirL,StartDir);
    sprintf(fileL,FindFile);
    }

    WIN32_FIND_DATA DirPathL;//variable to hold the file information for
    found files
    HANDLE hDirL = INVALID_HANDLE_VALUE;//file handle variable

    cout << endl << dirL << endl;// output of the current search direcotry

    //This if statement deals with finding the FILES within the current
    //search directory. This is done so that the files in the search
    //directory are looked at before moving on to a new directory.
    hDirL = FindFirstFile( fileL, &DirPathL );//finds the first file
    matching the search criteria
    if( hDirL != INVALID_HANDLE_VALUE )//makes sure it is a valid file
    handle
    {
    //do/while loop to search for files within the current search
    directory
    //skips any sub-directories found and the 2 root files of a directory
    //. and .. Stops when there are no more files matching the search
    criteria
    do{
    //if statement to see if the found file is a sub-directory or a root
    directory
    if( !(DirPathL.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) &&
    strcmp( DirPathL.cFileName, "." ) &&
    strcmp( DirPathL.cFileName, ".." ))
    {

    /*-------------------------------------------------------------------------*/
    /*----- THIS IS WHERE THE FILE MANIPULATION CODE SHOULD GO
    ----------------*/
    /*-------------------------------------------------------------------------*/
    sprintf( tmpL,dirL );//copies the current search directory to the
    tmpL buffer
    i = strcspn( tmpL,"*" );//find the first * character in the tmpL
    buffer
    tmpL[i] = NULL;//sets the position in the tmpL buffer to null which
    ends the string
    strcat( tmpL, DirPathL.cFileName );//copies the found file name to
    the end of the tmpL buffer
    cout << "\tFILE --> " << tmpL << endl;//outputs the tmpL buffer
    /*--------------------------------------------------------------------------*/
    /*--------------------------------------------------------------------------*/
    /*--------------------------------------------------------------------------*/
    }
    }while( FindNextFile( hDirL,&DirPathL ));//gets the next file
    matching the search criteria
    }

    //This if statement deals with finding the DIRECTORIES within the
    current
    //search directory. Once a sub-directory is found then it is moved
    into
    //and the search begins anew by first looking at the files within the
    //directory
    hDirL = FindFirstFile( dirL, &DirPathL );//finds the first file
    matching the search criteria
    if( hDirL != INVALID_HANDLE_VALUE )//makes sure it is a valid file
    handle
    {
    //do/while loop to search for sub-directories within the current
    search directory
    //skips any regular files found and the 2 root files of a directory
    //. and .. Stops when there are no more files matching the search
    criteria
    do {
    //if statement to see if the found file is a sub-directory or a root
    directory
    if(( DirPathL.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) &&
    strcmp(DirPathL.cFileName, ".") &&
    strcmp(DirPathL.cFileName, ".."))
    {
    /*----------------------------------------------------------------------------------*/
    /*-------- THIS IS WHERE THE DIRECTORY MANIPULATION CODE SHOULD GO
    -----------------*/
    /*----------------------------------------------------------------------------------*/
    sprintf(tmpL,dirL);//copies the current search directory to the
    tmpL buffer
    i = strcspn(tmpL,"*");//find the first * character in the tmpL
    buffer
    tmpL[i] = NULL;//sets the position in the tmpL buffer to null which
    ends the string
    strcat( tmpL, DirPathL.cFileName );//copies the found sub-directory
    to the end of the tmpL buffer
    RecursiveFileSearch( FindFile, tmpL);//recursively calls the
    function again using the new sub-directory
    /*----------------------------------------------------------------------------------*/
    /*----------------------------------------------------------------------------------*/
    /*----------------------------------------------------------------------------------*/
    }
    }while ( FindNextFile(hDirL, &DirPathL ));//gets the next file
    matching the search criteria

    }
    else
    {
    cout << "\tERROR WHILE SEARCHING\n\n";//output error if the search
    file handle is invalid
    }

    //closes the file handle if it is not invalid
    if(hDirL != INVALID_HANDLE_VALUE)
    FindClose(hDirL);
    }


    Thanks in advance for any advice. Please remember that I am only
    wanting constructive critisism.


  2. Re: can you see a better way to do this? constructive critisism wanted

    enigma wrote:
    > Just take a look and let me know if you see a better way to do it.


    Just a small criticism: your function allocates a lot of extra memory on
    the stack unnecessarily at start of each invocation of the function.
    Every time it scans to a new directory depth it allocates the three
    256-byte buffers again so that if you are searching from the root of
    your hard-disk you could easily reach 5 directories deep and allocate
    4kb of memory just to store one filename! It should be possible to use
    only one buffer and either pass a pointer to it or make it static.

    - Neil

  3. Re: can you see a better way to do this? constructive critisism wanted

    Hmmm...that sounds like a good idea. So with what you are saying would
    it be better to declare the three arrays like so:

    static char buf1[256];
    static char buf2[256];
    static char buf3[256];

    Is that better or does that not fux what you were refering to?


  4. Re: can you see a better way to do this? constructive critisism wanted

    I actually tried this, just changing the 3 buffers to static and it
    doesn't work with the function. The buffers are used to hold the the
    path name's and if they are static then each call of the function will
    be using the same information and the search will not work. Each
    function needs it's own buffer to hold the updated information, with
    the way the function is written. That is part of why i was hoping to
    get some better ideas on how to do the search.


  5. Re: can you see a better way to do this? constructive critisism wanted

    enigma writes:
    >Hello,
    >
    >I doubt that you have read an earlier post of mine regarding a method


    [snip]

    >program. Just take a look and let me know if you see a better way to do
    >it.
    >
    >// recursive function that searches the directory tree
    >// starting at a designated starting directory. If not
    >// starting directory is given then the search begins
    >// at the root
    >void
    >RecursiveFileSearch( char *FindFile = "*.*", char *StartDir = "*.*")


    Observation: if it accepts quoted strings, it should be const char *
    rather than simple char * . Also, you will not be modifying the
    caller's data, so using const helps you avoid bugs.

    Also, it's more appropriate for the starting directory to default to
    ".", i.e. the current directory.

    >{
    > int i = -1;//, j = -1;
    > char dirL[255], tmpL[255], fileL[255];//char buffers for holding names


    What is 255 here? It's entirely feasible for the full path to a file to
    exceed 255 characters. Use MAX_PATH, which is slightly bigger than 255.
    A full path + filename can be up to 255(max path within drive, including
    filename) + 3 (drive letter, colon, backslash) + 1 (trailing '\000')

    Also, both i and dirL are unnecessary once you change the default
    StartDir to "." and ban wildcards in the directory. You can just use
    StartDir instead of dirL.

    > //clearing out the memory of the char buffers to make sure no junk is
    >accidently loaded
    > ZeroMemory(dirL,sizeof(dirL));
    > ZeroMemory(fileL,sizeof(fileL));
    > ZeroMemory(tmpL,sizeof(tmpL));


    This really isn't necessary. As far as the various string-related
    functions you use are concerned, strings end at the first '\000'
    character, and nothing beyond that counts. The code you have below
    actually builds the right data in these buffers, so you are OK.

    > //checks to see if the search directory is the default value
    > //if it is not, then \*.* is added to the end of the directory
    > //name, otherwise the values are copied over as is
    > if(strcmp(StartDir,"*.*"))


    Stylistic point - strcmp is an error-prone function to call correctly,
    as its return value is "true" when the strings are not equal, and
    "false" when they are equal. Help yourself by explicitly comparing the
    return value to 0:

    strcmp method std::string method
    strcmp(a,b) != 0 a != b
    strcmp(a,b) == 0 a == b
    strcmp(a,b) > 0 a > b
    etc.

    As you can see, if you do the explicit comparison, you can see the
    operation you are doing.

    > {
    > sprintf(dirL,"%s\\*.*",StartDir);
    > sprintf(fileL,"%s\\%s",StartDir,FindFile);
    > }
    > else
    > {
    > sprintf(dirL,StartDir);
    > sprintf(fileL,FindFile);
    > }


    If you change the default StartDir to ".", you can discard this entire
    if() statement, and simply use the if-branch to build dirL and fileL.

    > WIN32_FIND_DATA DirPathL;//variable to hold the file information for
    >found files
    > HANDLE hDirL = INVALID_HANDLE_VALUE;//file handle variable


    Don't waste time here - you're about to overwrite this initialisation
    value, so it's wasted.

    > cout << endl << dirL << endl;// output of the current search direcotry
    >
    > //This if statement deals with finding the FILES within the current
    > //search directory. This is done so that the files in the search
    > //directory are looked at before moving on to a new directory.
    > hDirL = FindFirstFile( fileL, &DirPathL );//finds the first file
    >matching the search criteria
    > if( hDirL != INVALID_HANDLE_VALUE )//makes sure it is a valid file
    >handle
    > {
    > //do/while loop to search for files within the current search
    >directory
    > //skips any sub-directories found and the 2 root files of a directory
    > //. and .. Stops when there are no more files matching the search
    >criteria
    > do{
    > //if statement to see if the found file is a sub-directory or a root
    >directory


    It's quite possible for a directory to be marked read-only, and this
    test will not work the way you intend if it is. Instead, use this:

    if( !(DirPathL.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
    {
    ....
    }

    "." and ".." *are* directories, and will be skipped as a matter of
    course if the directory attribute test is done correctly.

    > if( !(DirPathL.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) &&
    > strcmp( DirPathL.cFileName, "." ) &&
    > strcmp( DirPathL.cFileName, ".." ))
    > {
    >
    >/*-------------------------------------------------------------------------*/
    >/*----- THIS IS WHERE THE FILE MANIPULATION CODE SHOULD GO
    >----------------*/
    >/*-------------------------------------------------------------------------*/
    > sprintf( tmpL,dirL );//copies the current search directory to the
    >tmpL buffer


    NEVER sprintf() with an unknown string in the second parameter. If dirL
    contains the sequence "%s", you are in *deep* trouble here.

    For what you are doing, strcpy() is much better than sprintf().

    > i = strcspn( tmpL,"*" );//find the first * character in the tmpL
    >buffer
    > tmpL[i] = NULL;//sets the position in the tmpL buffer to null which
    >ends the string
    > strcat( tmpL, DirPathL.cFileName );//copies the found file name to
    >the end of the tmpL buffer


    Of course, it would look better like this:

    sprintf( tmpL, "%s\\%s", StartDir, DirPathL.cFileName );

    This assumes that you change the default StartDir to ".".

    > cout << "\tFILE --> " << tmpL << endl;//outputs the tmpL buffer
    >/*--------------------------------------------------------------------------*/
    >/*--------------------------------------------------------------------------*/
    >/*--------------------------------------------------------------------------*/
    > }
    > }while( FindNextFile( hDirL,&DirPathL ));//gets the next file
    >matching the search criteria


    Here: FindClose( hDirL );

    Do this inside this if(). If you don't do it here, you leak a Find
    handle because the next thing you do is overwrite hDirL.

    > }
    >
    > //This if statement deals with finding the DIRECTORIES within the
    >current
    > //search directory. Once a sub-directory is found then it is moved
    >into
    > //and the search begins anew by first looking at the files within the
    > //directory
    > hDirL = FindFirstFile( dirL, &DirPathL );//finds the first file
    >matching the search criteria
    > if( hDirL != INVALID_HANDLE_VALUE )//makes sure it is a valid file
    >handle
    > {
    > //do/while loop to search for sub-directories within the current
    >search directory
    > //skips any regular files found and the 2 root files of a directory
    > //. and .. Stops when there are no more files matching the search
    >criteria
    > do {
    > //if statement to see if the found file is a sub-directory or a root
    >directory


    The same comment about read-only directories applies here as above:

    if( (attributes & FILE_ATTRIBUTE_DIRECTORY) &&
    strcmp( name, "." ) != 0 &&
    strcmp( name, ".." ) != 0 )

    This time you *do* have to check for "." and "..", of course.

    > if(( DirPathL.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) &&
    > strcmp(DirPathL.cFileName, ".") &&
    > strcmp(DirPathL.cFileName, ".."))
    > {
    >/*---------------------------------------------------------------------
    >-------------*/
    >/*-------- THIS IS WHERE THE DIRECTORY MANIPULATION CODE SHOULD GO
    >-----------------*/
    >/*---------------------------------------------------------------------
    >-------------*/
    > sprintf(tmpL,dirL);//copies the current search directory to the
    >tmpL buffer
    > i = strcspn(tmpL,"*");//find the first * character in the tmpL
    >buffer
    > tmpL[i] = NULL;//sets the position in the tmpL buffer to null which
    >ends the string
    > strcat( tmpL, DirPathL.cFileName );//copies the found sub-directory
    >to the end of the tmpL buffer


    As above, change the default StartDir to ".", and use this instead of
    the above section:

    sprintf( tmpL, "%s\\%s", StartDir, DirPathL.cFileName );

    > RecursiveFileSearch( FindFile, tmpL);//recursively calls the
    >function again using the new sub-directory
    >/*---------------------------------------------------------------------
    >-------------*/
    >/*---------------------------------------------------------------------
    >-------------*/
    >/*---------------------------------------------------------------------
    >-------------*/
    > }
    > }while ( FindNextFile(hDirL, &DirPathL ));//gets the next file
    >matching the search criteria
    >
    > }
    > else
    > {
    > cout << "\tERROR WHILE SEARCHING\n\n";//output error if the search
    >file handle is invalid
    > }
    >
    > //closes the file handle if it is not invalid
    > if(hDirL != INVALID_HANDLE_VALUE)
    > FindClose(hDirL);


    Move the FindClose inside the main if() above, and you don't need
    another if().

    >}
    >
    >
    >Thanks in advance for any advice. Please remember that I am only
    >wanting constructive critisism.
    >


    --
    SteveR
    (throw away the dustbin, send to stever@... instead)

    Humans are way too stupid to be dumb animals.
    http://www.accidentalcreditor.org.uk/

  6. Re: can you see a better way to do this? constructive critisism wanted

    Thanks a lot Steve! That is exactly the kind of critisim I was hoping
    to get. I really appreciate you taking the time to look over my code
    and give me such detailed information.

    Thanks!
    SteveR wrote:
    > enigma writes:
    > >Hello,
    > >
    > >I doubt that you have read an earlier post of mine regarding a

    method
    >
    > [snip]
    >
    > >program. Just take a look and let me know if you see a better way to

    do
    > >it.
    > >
    > >// recursive function that searches the directory tree
    > >// starting at a designated starting directory. If not
    > >// starting directory is given then the search begins
    > >// at the root
    > >void
    > >RecursiveFileSearch( char *FindFile = "*.*", char *StartDir = "*.*")

    >
    > Observation: if it accepts quoted strings, it should be const char *
    > rather than simple char * . Also, you will not be modifying the
    > caller's data, so using const helps you avoid bugs.
    >
    > Also, it's more appropriate for the starting directory to default to
    > ".", i.e. the current directory.
    >
    > >{
    > > int i = -1;//, j = -1;
    > > char dirL[255], tmpL[255], fileL[255];//char buffers for

    holding names
    >
    > What is 255 here? It's entirely feasible for the full path to a file

    to
    > exceed 255 characters. Use MAX_PATH, which is slightly bigger than

    255.
    > A full path + filename can be up to 255(max path within drive,

    including
    > filename) + 3 (drive letter, colon, backslash) + 1 (trailing '\000')
    >
    > Also, both i and dirL are unnecessary once you change the default
    > StartDir to "." and ban wildcards in the directory. You can just use
    > StartDir instead of dirL.
    >
    > > //clearing out the memory of the char buffers to make sure no

    junk is
    > >accidently loaded
    > > ZeroMemory(dirL,sizeof(dirL));
    > > ZeroMemory(fileL,sizeof(fileL));
    > > ZeroMemory(tmpL,sizeof(tmpL));

    >
    > This really isn't necessary. As far as the various string-related
    > functions you use are concerned, strings end at the first '\000'
    > character, and nothing beyond that counts. The code you have below
    > actually builds the right data in these buffers, so you are OK.
    >
    > > //checks to see if the search directory is the default value
    > > //if it is not, then \*.* is added to the end of the

    directory
    > > //name, otherwise the values are copied over as is
    > > if(strcmp(StartDir,"*.*"))

    >
    > Stylistic point - strcmp is an error-prone function to call

    correctly,
    > as its return value is "true" when the strings are not equal, and
    > "false" when they are equal. Help yourself by explicitly comparing

    the
    > return value to 0:
    >
    > strcmp method std::string method
    > strcmp(a,b) != 0 a != b
    > strcmp(a,b) == 0 a == b
    > strcmp(a,b) > 0 a > b
    > etc.
    >
    > As you can see, if you do the explicit comparison, you can see the
    > operation you are doing.
    >
    > > {
    > > sprintf(dirL,"%s\\*.*",StartDir);
    > > sprintf(fileL,"%s\\%s",StartDir,FindFile);
    > > }
    > > else
    > > {
    > > sprintf(dirL,StartDir);
    > > sprintf(fileL,FindFile);
    > > }

    >
    > If you change the default StartDir to ".", you can discard this

    entire
    > if() statement, and simply use the if-branch to build dirL and fileL.
    >
    > > WIN32_FIND_DATA DirPathL;//variable to hold the file

    information for
    > >found files
    > > HANDLE hDirL = INVALID_HANDLE_VALUE;//file handle variable

    >
    > Don't waste time here - you're about to overwrite this initialisation
    > value, so it's wasted.
    >
    > > cout << endl << dirL << endl;// output of the current search

    direcotry
    > >
    > > //This if statement deals with finding the FILES within the

    current
    > > //search directory. This is done so that the files in the

    search
    > > //directory are looked at before moving on to a new

    directory.
    > > hDirL = FindFirstFile( fileL, &DirPathL );//finds the first

    file
    > >matching the search criteria
    > > if( hDirL != INVALID_HANDLE_VALUE )//makes sure it is a valid

    file
    > >handle
    > > {
    > > //do/while loop to search for files within the

    current search
    > >directory
    > > //skips any sub-directories found and the 2 root

    files of a directory
    > > //. and .. Stops when there are no more files

    matching the search
    > >criteria
    > > do{
    > > //if statement to see if the found file is a

    sub-directory or a root
    > >directory

    >
    > It's quite possible for a directory to be marked read-only, and this
    > test will not work the way you intend if it is. Instead, use this:
    >
    > if( !(DirPathL.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
    > {
    > ...
    > }
    >
    > "." and ".." *are* directories, and will be skipped as a matter of
    > course if the directory attribute test is done correctly.
    >
    > > if( !(DirPathL.dwFileAttributes ==

    FILE_ATTRIBUTE_DIRECTORY) &&
    > > strcmp( DirPathL.cFileName,

    "." ) &&
    > > strcmp(

    DirPathL.cFileName, ".." ))
    > > {
    > >

    >
    >/*-------------------------------------------------------------------------*/
    > >/*----- THIS IS WHERE THE FILE MANIPULATION CODE SHOULD GO
    > >----------------*/

    >
    >/*-------------------------------------------------------------------------*/
    > > sprintf( tmpL,dirL );//copies the

    current search directory to the
    > >tmpL buffer

    >
    > NEVER sprintf() with an unknown string in the second parameter. If

    dirL
    > contains the sequence "%s", you are in *deep* trouble here.
    >
    > For what you are doing, strcpy() is much better than sprintf().
    >
    > > i = strcspn( tmpL,"*" );//find the

    first * character in the tmpL
    > >buffer
    > > tmpL[i] = NULL;//sets the position in

    the tmpL buffer to null which
    > >ends the string
    > > strcat( tmpL, DirPathL.cFileName

    );//copies the found file name to
    > >the end of the tmpL buffer

    >
    > Of course, it would look better like this:
    >
    > sprintf( tmpL, "%s\\%s", StartDir, DirPathL.cFileName );
    >
    > This assumes that you change the default StartDir to ".".
    >
    > > cout << "\tFILE --> " << tmpL <<

    endl;//outputs the tmpL buffer
    >
    >/*--------------------------------------------------------------------------*/
    >
    >/*--------------------------------------------------------------------------*/
    >
    >/*--------------------------------------------------------------------------*/
    > > }
    > > }while( FindNextFile( hDirL,&DirPathL ));//gets the

    next file
    > >matching the search criteria

    >
    > Here: FindClose( hDirL );
    >
    > Do this inside this if(). If you don't do it here, you leak a Find
    > handle because the next thing you do is overwrite hDirL.
    >
    > > }
    > >
    > > //This if statement deals with finding the DIRECTORIES within

    the
    > >current
    > > //search directory. Once a sub-directory is found then it is

    moved
    > >into
    > > //and the search begins anew by first looking at the files

    within the
    > > //directory
    > > hDirL = FindFirstFile( dirL, &DirPathL );//finds the first

    file
    > >matching the search criteria
    > > if( hDirL != INVALID_HANDLE_VALUE )//makes sure it is a valid

    file
    > >handle
    > > {
    > > //do/while loop to search for sub-directories within

    the current
    > >search directory
    > > //skips any regular files found and the 2 root files

    of a directory
    > > //. and .. Stops when there are no more files

    matching the search
    > >criteria
    > > do {
    > > //if statement to see if the found file is a

    sub-directory or a root
    > >directory

    >
    > The same comment about read-only directories applies here as above:
    >
    > if( (attributes & FILE_ATTRIBUTE_DIRECTORY) &&
    > strcmp( name, "." ) != 0 &&
    > strcmp( name, ".." ) != 0 )
    >
    > This time you *do* have to check for "." and "..", of course.
    >
    > > if(( DirPathL.dwFileAttributes ==

    FILE_ATTRIBUTE_DIRECTORY) &&
    > > strcmp(DirPathL.cFileName,

    ".") &&
    > >

    strcmp(DirPathL.cFileName, ".."))
    > > {

    >
    >/*---------------------------------------------------------------------
    > >-------------*/
    > >/*-------- THIS IS WHERE THE DIRECTORY MANIPULATION CODE SHOULD GO
    > >-----------------*/

    >
    >/*---------------------------------------------------------------------
    > >-------------*/
    > > sprintf(tmpL,dirL);//copies the

    current search directory to the
    > >tmpL buffer
    > > i = strcspn(tmpL,"*");//find the

    first * character in the tmpL
    > >buffer
    > > tmpL[i] = NULL;//sets the position in

    the tmpL buffer to null which
    > >ends the string
    > > strcat( tmpL, DirPathL.cFileName

    );//copies the found sub-directory
    > >to the end of the tmpL buffer

    >
    > As above, change the default StartDir to ".", and use this instead of
    > the above section:
    >
    > sprintf( tmpL, "%s\\%s", StartDir, DirPathL.cFileName );
    >
    > > RecursiveFileSearch( FindFile,

    tmpL);//recursively calls the
    > >function again using the new sub-directory

    >
    >/*---------------------------------------------------------------------
    > >-------------*/

    >
    >/*---------------------------------------------------------------------
    > >-------------*/

    >
    >/*---------------------------------------------------------------------
    > >-------------*/
    > > }
    > > }while ( FindNextFile(hDirL, &DirPathL ));//gets the

    next file
    > >matching the search criteria
    > >
    > > }
    > > else
    > > {
    > > cout << "\tERROR WHILE SEARCHING\n\n";//output error

    if the search
    > >file handle is invalid
    > > }
    > >
    > > //closes the file handle if it is not invalid
    > > if(hDirL != INVALID_HANDLE_VALUE)
    > > FindClose(hDirL);

    >
    > Move the FindClose inside the main if() above, and you don't need
    > another if().
    >
    > >}
    > >
    > >
    > >Thanks in advance for any advice. Please remember that I am only
    > >wanting constructive critisism.
    > >

    >
    > --
    > SteveR
    > (throw away the dustbin, send to stever@... instead)
    >
    > Humans are way too stupid to be dumb animals.
    > http://www.accidentalcreditor.org.uk/



+ Reply to Thread