LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why can I not delete my test file?

I wish to delete the text file I created in my earlier subVI and create a new file with the same name with new data. In the T38 Write Revised Datalog subVI I receive an error code 8 when I attempt to DELETE the existing file. Why do I get this error? How can I successfully delete the file so I can create a new file of the same name?
0 Kudos
Message 1 of 8
(3,034 Views)
(You don't need the "delete" if you subsequently open as "create/replace". Just wire the "advisory dialog" with a "false" to avoid the dialog, delete is implicit.)

I think your problem is due to how you "close" the file in "T38 Write Init Datalog.vi". Basically, you "open" in once more, then close that second instance, meaning the "open" in the upper left still holds onto the file, preventing deletion. Remove the second "open" and close the file with the original refnum (see attached example).

There is a second problem, though: Can you explain why the main program contains a while loop? If the boolean is false, you'll continually try to delete the file again while it never gets closed, giving you the same error from the second iteration on. You don't reall
y want to delete/open/"write the SAME data" over and over again as fast as the computer allows, right?
0 Kudos
Message 2 of 8
(3,032 Views)
Sorry, wrong version. Here is the example as LV6.1
0 Kudos
Message 3 of 8
(3,032 Views)
The same basic problem that was already mentioned exists with your modified code. You are trying to open the same file twice without closing it. The VI "Write Characters to File.vi" attempts to open the file inside it, but you already have it open.

See the attached corrected version.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 4 of 8
(3,032 Views)
Mike: Yes, I agree, the code is buggier than an ant farm elsewhere. My 10 second modification eliminates the error generated by the "delete file", which was the original question.

Actually, the "write chars to file.vi" opens and closes the file and no error is generated even if it has been opened elsewhere earlier. ugly! If both instances are closed, the delete can proceed.
0 Kudos
Message 5 of 8
(3,032 Views)
Actually the main program simulates my needs in the real application. As my testing progresses I will be having to rewrite the data to the file many times. The true application is conducting a very long test and I need to periodically undate the test data file in the event the test aborts. If I could rewrite the text file in place it would be great. However, being a text file I don't believe that is possible. Thus I will be closing the file deleting it and rewriting it.

All suggestions are appreciated.
0 Kudos
Message 6 of 8
(3,033 Views)
>Actually, the "write chars to file.vi" opens and closes the file and no error is generated even if it has been opened elsewhere earlier. ugly!

By default, LabVIEW opens files with deny mode "none" e.g. other processes are allowed to open/read/write the file simultaneously. Not only is this seldom required but it causes errors when the file is opened for a long time. Other applications like Office FastFind, virus scanners and backup applications can try to access the file while you are using it. And when they open the file they can actulally deny you further access to the file the time they use it, causing errors 8 in your application.

The best practice is to open the file with deny mode "Deny write/read" that gives you exclusive ac
cess while you are using it. Unfortunately, high level file VIs like "Open/Create/Replace File.vi" don't allow to select the deny mode and use the default "deny none".


LabVIEW, C'est LabVIEW

0 Kudos
Message 7 of 8
(3,032 Views)
Actually you can use the "Flush File" function that writes any cached data on disk and updates the directory entry of the file. In the event of an unexpected abort, the you'll recover the file from the last Flush. After the fulsh you resume normal write operations to append new data.

When you open an existing file to append data, you can position the file marker to the end of the file. That leaves existing data on the file and following writes on the file are appended to the end. Use the advanced file function "Seek" to position the file marker at the end of the file.


LabVIEW, C'est LabVIEW

0 Kudos
Message 8 of 8
(3,033 Views)