LabWindows/CVI

取消
显示结果 
搜索替代 
您的意思是: 

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 项奖励
1 条消息(共 5 条)
6,828 次查看
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
2 条消息(共 5 条)
6,825 次查看
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 项奖励
3 条消息(共 5 条)
6,796 次查看
never mind bout the compiler problem. 

and your solution works perfectly.  thanks again!
0 项奖励
4 条消息(共 5 条)
6,786 次查看
No problem.  Glad you figured out your include issues without too much pain.
0 项奖励
5 条消息(共 5 条)
6,783 次查看