LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Remove extra file contents / Set End of File

Hello All;
 
I have an application which needs to read and write to/from text files.  The Config VIs do not give me what I need, and so I am using the File I/O (Open File, Close File, Read Text File, Write Text File) and Adv File Functions (Set File Position).  My general flow is this:
 
     Open File --> Read from Text File (Use Spreadsheet String to Array to itemise everything) --> Manipulate the String Array --> Set File Position = 0 from Start --> Write to Text File --> Close File
 
Having said that, if my reworked string array is shorter (i.e. smaller index) than my original, when I write to file, not everything is replaced.  Basically, it only replaces the exact number of characters, if you will, that it needs to.  See attached text example (in this case, the !end is listed twice...)...
 
Is there a way to set the End of File (eof) such that the file ends immediately after I write information?  Is there a way to "empty" the file immediately before writing?  I suppose an alternative would be to write to a temporary file, and replace the original file with the (slightly smaller) temporary file, but I'd rather only use the single file (if possible).
 
Anyway, any help would be appreciated!
 
Thanks in advance,
D. J. Hanna
0 Kudos
Message 1 of 3
(2,797 Views)
Depending on your LabVIEW version:

8.x : In the Advanced File Functions Palette:  Set File Size

7.x and earlier: In the Advanced File Functions Palette:  EOF
0 Kudos
Message 2 of 3
(2,794 Views)

That did it; thanks!

For anyone else who had the same issues, using LV8.2, do the following:

(1) After writing to text file, use "Get File Position.vi" to get the current position of the file marker;

(2) Use the "Set File Size.vi" and input the current file marker position (from (1)) as the offset;

(3) Close the file.

0 Kudos
Message 3 of 3
(2,766 Views)