LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

quick question on renaming file after fclose()

ok..im trying to rename a text file after creating it, without exiting the program. i put a fclose(file) on a command button, and try to rename the file after pressing the button. If I try to rename it says file is in use. the weird thing is i made a smaller test program to see if I can rename the file after fclose() and it works fine. but I can't get it to work im my original program. i also used a fflush() before fclose, but no luck. Thanks for any help 
0 Kudos
Message 1 of 3
(3,562 Views)
I have already found a similar error while trying to delete a file immediately after closing it but found no definitive answer in the forums: the whole discussion can be found here. It that case a double-disk with mirroring system was present which could introduce some more latency after CloseFile returns.
I ended up adding some Delay between CloseFile and DeleteFile, but maybe a more efficient solution could be to place a little loop that periodically triese to rename and exits only if no error is found.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(3,550 Views)

hmm...ok. dont know exactly why this worked, but I fixed it. I had a code like this in a cmd button

/*

 if(out=fopen("result.txt", "r")) 
  {
    if(!(ConfirmPopup("WARNING", "r u sure u wanna overwrite result?(if not choose NO and rename file))")))
    return 0;
  
  }
 */
     
     
      GetCtrlVal(panelHandle, PANEL_RING,&temp);
     keithley_id="ASRL1::INSTR";
     keithley_id[4]=temp ;
  
     func=KE2700_VAL_FREQ;
 // printf("%c %c %d xx", keithley_id[4], temp, func);
 // getchar();
 out=fopen("result.txt", "a+");

 

 

most of the part was just a routine to test if a file exists. I noticed i was getting non fatal run time error for that, when the file didnt exist. after commenting it out and using fclose() I seem to be able to rename the file. any ideas what is going on here? I also tried to set the *out to NULL, but that didnt let me rename either.

0 Kudos
Message 3 of 3
(3,532 Views)