LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem when i use function GetFirstFile and GetNextFile

I attached my source code as below.
 
int CheckIniFileOnDisk (SysSetPtr ThisPtr,char *Directory)
{ char FileNam[MAX_FILENAME_LEN];
  char Dir[MAX_DIRNAME_LEN];
  char Buff[1000];
 int  End = 1;
 int  Err;
 
  Fmt (Dir, "%s<%s\\*.ini", Directory);
 if (GetFirstFile (Dir, 1, 0, 1, 0, 0, 0, FileNam) !=0) {InterfaceMessage(ThisPtr,"Can not find file or file access error!"); return(-1); }                  // get the filename from appointed directory
  
 Fmt(Buff,"%s< Find file %s on root,Fetch information...",FileNam);
 InterfaceMessage(ThisPtr,Buff);
 Fmt (Buff, "%s<%s\\%s", Directory,FileNam);
   
 do
  {
   if (FetchIniFile(ThisPtr,Buff)) InterfaceMessage(ThisPtr,"The parameter is not match with selected 12NC, check next file");
   else { End = 0; break;}
   
   if (GetNextFile (FileNam) !=0) {InterfaceMessage(ThisPtr,"No more files found that match criteria"); End = 0; return(-1);} 
     
   Fmt(Buff,"%s< Find file %s on root,Fetch information...",FileNam);
   InterfaceMessage(ThisPtr,Buff);
   Fmt (Buff, "%s<%s\\%s", Directory,FileNam);
  
   }while (End);
  
 return(0);
 }    
 
The problem is the GetNextFile alway return -1 after i call FetchIniFile function. if i skip this function, GetNextFile work propery. Anyone could advise?
 
Thanks in advance!
 
Gerry
0 Kudos
Message 1 of 10
(5,097 Views)
Gerry,

It looks like FetchIniFile is a function that you wrote.  If this function (or any function further up the program stack) calls GetFirstFile/GetNextFile, it will interfere with the GetNextFile calls in CheckIniFileOnDisk.  If this is the case, you may want to rewrite CheckIniFileOnDisk to copy and temporarily store all the .ini file paths found by GetFirstFile/GetNextFile before ever calling FetchIniFile.

Hope this helps.

Mert A.
National Instruments
0 Kudos
Message 2 of 10
(5,075 Views)

Thanks Mert.

 you are right, i call GetFirstFile again in FetchlniFile function. because the lni file only contain the path of parameter file. I want to call GetFirstFile to check the parameter file is in specified path or not.  Now it seems like i can not use this function anymore. could you tell me which function is similar with this one?

 

Gerry

0 Kudos
Message 3 of 10
(5,062 Views)
Gerry,

You can use the GetFileInfo function in the Formatting and I/O library (include formatio.h).  This function returns 1 if the file exists, or 0 if it does not.

Hope this helps.

Mert A.
National Instruments
0 Kudos
Message 4 of 10
(5,054 Views)

Good, I have solved problem , thanks.

bye the way. i find there is a function Findclose on Windows API, why i can not find this function in CVI?

 

Gerry

0 Kudos
Message 5 of 10
(5,051 Views)
The Windows API find functions (e.g. FindFirstFile) use handles that allow multiple searches to be performed independently.  FindClose is called on a handle to notify the library that you are done with the search, and the resources associated with that search may be freed.  Because the GetFirst/NextFile functions in the CVI Utility library do not support concurrent, independent searching, there are no handles and no resources to be freed by a FindClose-like function.

Mert A.
National Instruments
0 Kudos
Message 6 of 10
(5,037 Views)
All right. Thanks Smiley Wink
0 Kudos
Message 7 of 10
(5,021 Views)
All right. Thanks Smiley Wink
0 Kudos
Message 8 of 10
(5,020 Views)
All right. Thanks Smiley Wink
0 Kudos
Message 9 of 10
(5,019 Views)

@Mert_A. wrote:
The Windows API find functions (e.g. FindFirstFile) use handles that allow multiple searches to be performed independently.  FindClose is called on a handle to notify the library that you are done with the search, and the resources associated with that search may be freed.  Because the GetFirst/NextFile functions in the CVI Utility library do not support concurrent, independent searching, there are no handles and no resources to be freed by a FindClose-like function.

Thanks for clarifying this.  I found out the hard way.  I was using a GetFirst/NextFile loop at the top, and then inside this loop, doing another GetFirst/NextFile to get a group of specific files in that group.  Nope, doesn't work for the reasons you noted.

 

Is there a better way to go about nested file path finding?

0 Kudos
Message 10 of 10
(2,962 Views)