Here's the scenario:
Setup.vi launches Acquire.vi dynamically. Acquire.vi creates the file Temp.dat which is used to store data until it can be safely written to the final data file (time consuming scans are occurring and if the computer crashes for whatever reason, Temp.dat is used to recover what was already acquired and to continue scanning from there).
Acquire.vi creates Temp.dat using the New File function (with Overwrite = True) and stores the reference in a cluster which is accessed to write to the file and then close it and delete it at the end of the acquisition.
Because the reference is in a cluster and because I always use Unbundle by Name, I was able to change the name of the reference in the cluster to find every instance of it (thus verifying that Temp.dat wasn't being opened more than once). However, no matter what I do, after I Close the reference (which returns with no error), I cannot delete the file (error 8).
Acquire.vi exits (unloading it from memory). If Setup.vi is still running, I also cannot delete the file from Windows Explorer. Once I exit Setup.vi (with LabVIEW still running, but Setup.vi loaded but not running), I CAN delete Temp.dat in Explorer. All of this is in LabVIEW 6.1.
Now here's the kicker: the same code loaded into LabVIEW 7.0 DOES manage to delete Temp.dat without any problem.
I cannot understand how this can be. Even if I didn't close the reference, once Acquire.vi stops running and is no longer in memory, I should be able to delete the file in Explorer (I confirmed this by creating a small VI which creates a temp file- as long as the VI is running I can't delete the file- once the VI stops running, I can delete it even if I don't close the reference to the file in the VI).
Furthermore, Setup.vi only accesses Temp.dat once- when it starts up it looks to see if Temp.dat exists (if it does, it reads from it, stores it in a real data file and deletes it). How is it possible that Temp.dat cannot be deleted while Setup.vi is running when Setup.vi has no reference to Temp.dat? None of this makes any sense.
If anyone has ANY idea why this might be (setting permissions didn't seem to help), I would be most grateful. One last comment: Acquire.vi also creates a file called TempHdr.dat (which holds a temporary copy of the data's header- it is located in the same directory as Temp.dat). However, this file is created and closed immediately and is deleted successfully (in LabVIEW 6.1) before Acquire.vi exits. Other than having Temp.dat's reference open all the time and written to at the end of each scan, there's no difference between how the files are created, closed and deleted.
If you've made it this far, I'm impressed. If you have ANY idea what's going on, I will be eternally grateful...
-E. Blasberg iDAQ Solutions Ltd.
