urgent help needed please

Sadaf
Sadaf used Ask the Experts™
on
hi!
i am trying to list all my files in a folder..that i can do
 but problem is i also want to do this..
if there is a folder inside a folder i want to list all the files in that folder too...
want to list files from inside the folder too,,,

      WIN32_FIND_DATA FileData;
      HANDLE hFile;
      char * fname;
          
      hFile = FindFirstFile(dPath,&FileData);
   
      if ( INVALID_HANDLE_VALUE == hFile )
      {
            puts("No files");
            return false;
      }

   
   
 
      while(true)
      {
            fname = FileData.cFileName;
        puts(fname);
            geturl(fname);
            if ( 0 == FindNextFile(hFile, &FileData ) )
                  break;
      }
      
      return true;
}

need help...
regards
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006

Commented:
same question --- look at this, this will solve your problem

http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_10347814.html

Top Expert 2006
Commented:
this was the solution posted by expert makerp in that question

/*
this function recursivly scan directries. .

i done this in VC++ on NT 4.0
*/

#include <stdio.h>
#include <io.h>


int scan_path(char *path)
{
    char spath[256];
    struct _finddata_t ff;
    long fhandle;
   
     sprintf(spath,"%s\\*",path);
    fhandle=_findfirst(spath,&ff);
    if(fhandle==-1L)
    {
         printf("Bad path\n");
         return -1;
    }
    else
    {
         /* loop through each etry in the dir */
         while(!_findnext(fhandle,&ff))
      {
              /* if its a sub-dir then recursivly call our self*/
              if(ff.attrib&_A_SUBDIR)
              {
                    if(strcmp(ff.name,".."))
                    {
                           sprintf(spath,"%s\\%s",path,ff.name);
                           scan_path(path2);
                    }
              }
              else
              {
                    /* if its a file then */
                    if(ff.attrib^_A_SYSTEM)
                    {
                           /* in here you will have to check the extension */
                           printf("Found File %s\n",ff.name);
                    }
              }
         }
    }
    return 1;
}

Author

Commented:
thanks for the help..i tried this code ..
i cant figure out how am i suppose to give the path,,,
i tried scan_path("C:\\Documents and Settings");  as well as scan_path("C:\\Documents and Settings\\");
but got error bad name...
how should i give the path,
regards
Top Expert 2006

Commented:
scan_path("C:\\Documents and Settings");  should have worked fine since trailing \\ is being added by the program

I am not too proficient on win ... but try using FindFirstFile in place of _findfirst
Top Expert 2006

Commented:
oh ... it may be the intervening space in Documents and Settings which may be causing the trouble

try creating a directory without spaces in C:\ and test for it ...

if it works fine, then i think escaping space characters will help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial