LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Open file for appending does not appear to work properly.

In LV 8 opening a file with Open/Create/Replace file where operation is set to open or create does not set the file pointer to the end of the file but the beginning.  So by default it does not append when set as such.  In order to append I now have to use the Set File Position VI to move the pointer to the end of the file.   In previous version of LV this was not necessary.  I was under the impression that selecting the open or create operation was the same as performing a fopen("somefilename", "at") in C and choosing replace or create would overwrite.  Am I missing something here?
 
 
0 Kudos
Message 1 of 8
(3,808 Views)
Are you sure you're not overlooking the input "append" in the VI you're using to write the file?

Opening the file has (to my knowledge) no impact on WHERE the file is written.  That is controlled by (logically enough) the write file VI.



Hope this helps

Shane.

Message Edited by shoneill on 04-26-2006 04:52 PM

Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 2 of 8
(3,802 Views)
No, I didn't forget the append field.  LV8 now has a newer VI Open/Create/Replace File which doesn't use the Append field.  I tried using the VI you showed and it has the same effect in LV8, you must use the pointer to move to the end of the file.  The new version can't be openned to view the code.  The version you showed can be an basically if the user selects to Open/Create this is considered an append operation and in earlier versions of LV it puts new data at the end of the file.  If the user selects Replace/Create this is considered to be an overwrite operation and it will destroy the previous content of the file.  LV 8 doesn't seem to work this way.  Regardless of which way the file is opened the result is the content is overwritten.  The difference here is that the Open/Create option places the file pointer to the beginning of the file and it overwrites however many bytes you write.  Not a good default option.
 
Bob
 
 
0 Kudos
Message 3 of 8
(3,787 Views)
Bob,

I don't have LabVIEW 8, so I'm speculating here.....

Are you saying that if I choose to "write characters to file" with "append" set to TRUE then where the data is written is dependent on how I opened the file?

If this is the case then I'd call it a bug.  This isn't a bad default option, this would be overriding an explicit request to append data to the file.

I personally don't use the Open Create Replace VI, because I consider it badly named so that the VI basically has an invalid file name under WinXP (This has apparently been fixed in LV 😎 and the "open" functionality is basically built into most write VIs anyway.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 4 of 8
(3,784 Views)

Shane,

   I pulled up an older application I had written to use the Write Character to File VI.  LV8 no longer shows it (or at least it is not easily found).  I ran it and it works the way it is supposed to.  Data is appended when requested.  I re-tested the newer VIs and they do not work as expected.  While there is no control for Appending, the documentation states that using Open/Create should do the appending.  While the contents of the file are not completely eliminated, the pointer is placed at the beginning of the file and when the results are written they overwrite the existing upto the number of bytes read in.  The results are definetly strange.  I wrote a new Vi which does the open and then moves the pointer to the end of the file to avoid this issue.

 

Bob

0 Kudos
Message 5 of 8
(3,779 Views)
Bob,

That sounds like it's a real problem.

As I've said, I don't have LV 8, but I'd report it as a bug if it's reproducible.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 6 of 8
(3,774 Views)

Hi

How did you manage to append data to an exist file? I did not understand how you said you solve your problem. I'm using LV 8 and I have spent hours on it, buit it still won't append data.

I used a Open/Create/Replace VI >> Set File Position >> Write to Binary File >> Close Vi. I also used a Get File Size VI as the Offset input to the Set File Position VI, but nothing is happening, it just overrides the existing data.

Need some help please.

This is a simple task in C or VB, but LV 8 is proving otherwise

0 Kudos
Message 7 of 8
(3,720 Views)

I was very tricky, but I sorted it the long way, as LV 8 has lost most of the most VI for the job. First I read the contents of the File then use it as a String Input to an Append True/False String VI, then the new data use use as the True input string to the Append True/False String VI, an Empty String was connected to the False Input and a a True Constant connected to the Selector Input of the Append True/False String VI. The Output of the Append True/False String VI is then save to the original file using a Write to Binary File VI.

Any body who as problem with LV 8 appending problem, and can't understand how I did it, let me know.

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