Link to home
Start Free TrialLog in
Avatar of Koderiter
Koderiter

asked on

finding files problem. using findfirst and findnext

I'm trying to get all the files in a directory and add them to a list. My problem is, is that the findnext function is not finding any more files in the directory even though I know there are more files. My goal is to find all the ds*.dbf files, but the code will only find 1 file and then exit. Can anybody see what is going on?

Thanks,

here is my code:

      struct ffblk fileinfo;
      int iDone;
      char fileName[30];
      char fileFolder[30];
      
      //find all dsfbsxxx.dbf
      sprintf(fileFolder,"scale\\data\\sale%d\\*.*",saleID);
      iDone = findfirst(fileFolder, &fileinfo, 0);
      while(!iDone)
      {
            sprintf(fileName, "scale\\data\\Sale%d\\%s",saleID, fileinfo.ff_name);
            AddFileToList(fileName);
            iDone = findnext(&fileinfo);
      }
ASKER CERTIFIED SOLUTION
Avatar of mikem_2au
mikem_2au

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I recommend you use a fully qualified path to test your code first, and once you have it working with a fully qualified path, you can then trouble shoot the problem as to where your executable is actually running from.
Avatar of Koderiter
Koderiter

ASKER

Thanks for your comments.. they have helped me understand better how the find function works. I fiqured out that the variables filename and filefolder were not declared to be big enough. I changed them to filename [50] and filefolder[50] and that did fixed it.  

Another Note: The reason that I did not declare a starting point for my path is that the program can be installed into an unknown directory, but the scale folder will always be in that directory.

Thanks again for your help.