findfirst, findnext ??

This is a discussion on findfirst, findnext ?? within the C++ Programming forums, part of the General Programming Boards category; Hi im using djgpp and want to use the findfirst and findnext to see if a file exists. It is ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    28

    findfirst, findnext ??

    Hi im using djgpp and want to use the findfirst and findnext to see if a file exists. It is in dos.h but I dont know how the function works, could somebody please help: findfirst(const char*, ffblk *, int) - thats what the compiler says but what is ffblk?

    Thanks
    ...

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,489
    Code:
    #include <stdio.h>
    #include <dir.h>
    #include <string.h>
    
    #define ALL_ATTS ( \
      FA_DIREC | \
      FA_ARCH )
    
    void walker ( char *path ) {
      struct ffblk finder;
      unsigned int res;
    
      for ( res = findfirst ( "*.*", &finder, ALL_ATTS );
            res == 0;
            res = findnext( &finder ) ) {
        if ( strcmp(finder.ff_name, ".") == 0 ) continue;  // current dir
        if ( strcmp(finder.ff_name, "..") == 0 ) continue; // parent dir
    
        // if its a directory, examine it
        // else compare the filename with the one we're looking for
        if ( finder.ff_attrib & FA_DIREC ) {
          char newpath[MAXPATH];
          strcpy( newpath, path );
          strcat( newpath, "\\" );
          strcat( newpath, finder.ff_name);
          chdir( finder.ff_name );
          walker( newpath );
          chdir( ".." );
        } else {
          if ( strcmp( finder.ff_name, "words.txt" ) == 0 ) {
            printf( "Found!!!" );
          }
        }
      }
    }
    
    int main ( ) {
      char *root = "\\";
      chdir( root );
      walker( root );
      return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. findfirst
    By jersey_gal in forum C Programming
    Replies: 14
    Last Post: 08-27-2008, 02:26 PM
  2. findfirst
    By Flip in forum C++ Programming
    Replies: 3
    Last Post: 01-01-2006, 10:42 AM
  3. getting filenames
    By madsmile in forum C++ Programming
    Replies: 4
    Last Post: 03-12-2002, 01:40 PM
  4. findfirst, findnext question...
    By Brian in forum Windows Programming
    Replies: 2
    Last Post: 01-27-2002, 08:28 AM
  5. findfirst, findnext.
    By Jamazon in forum C++ Programming
    Replies: 1
    Last Post: 10-22-2001, 10:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21