LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

GetFirstFile( ) not working for me.

i can get GetDir() and SetDir() to work right, and GetFileSize() returns correct value for appropriate file in the current directory

but GetFirstFile() just returns a -1 error code (no files found) ... and the uninitialized garbage in the string. 

what am i doing wrong?

thanks


    char directory[MAX_PATHNAME_LEN];
    char filename[MAX_PATHNAME_LEN];
    long errornumber, size;
      
    errornumber = GetDir(directory);
    printf("err: %i, %s\n",errornumber, directory);
    
    errornumber=GetFirstFile (directory,1,0,0,0,0,0,filename);
    printf("err: %i, %s\n",errornumber,filename);
    
    errornumber=GetFileSize("Error.c",&size);    
    printf("err: %i, %i\n",errornumber,size);

0 Kudos
Message 1 of 5
(6,483 Views)
Hi,

Actually, the first parameter to GetFirstFile cannot be just the path of the directory you want to search.  The function looks for files that match the search path, so if you want to look for all files directly under C:, you would pass "C:\*".  For all DLLs directly under C:, pass "C:\*.dll", and so on.  To do this, make the following change to your code:

    char directory[MAX_PATHNAME_LEN];
    char filename[MAX_PATHNAME_LEN];
    long errornumber, size;
      
    errornumber = GetDir(directory);
    printf("err: %i, %s\n",errornumber, directory);

    strcat(directory, "\\*");
    
    errornumber=GetFirstFile (directory,1,0,0,0,0,0,filename);
    printf("err: %i, %s\n",errornumber,filename);
    
    errornumber=GetFileSize(filename,&size);    
    printf("err: %i, %i\n",errornumber,size);

You should then be in business.

Hope that helps.

Mert A.
National Instruments
Message 2 of 5
(6,480 Views)
thank you, Mert

such a simple solution, but one I would have never guessed on my own.  thanks!

unfortunately i have since hosed my include paths for the compiler. when i tried to track down this original problem using the built in 'errno' variable, i somehow caused myself some really ugly new problems.

but ill leave discussion of my latest debacle to its separate thread. 

Message Edited by rjohnson on 12-06-2005 01:52 PM

0 Kudos
Message 3 of 5
(6,451 Views)
never mind bout the compiler problem. 

and your solution works perfectly.  thanks again!
0 Kudos
Message 4 of 5
(6,441 Views)
No problem.  Glad you figured out your include issues without too much pain.
0 Kudos
Message 5 of 5
(6,438 Views)