LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I write file to text file and manage its size ?

Hi
 
I would like to save string data to textfile and I'm using write to text file function to it. Is it possible to manage file sixe so that user could define maximum file size to text file? After this limit would be achieved, it would start writing to next file (default name +1) ? I am using labview 8.0 and I am a newbie so please help me...
 
HBu
0 Kudos
Message 1 of 6
(4,121 Views)
You would need to write your own subVI "Write to multiple text files.vi" that takes care of checking if the file size exceeds the limit you set. This VI of yours can use "Write to text file" to do the actual writing.

Tomi
--
Tomi Maila
0 Kudos
Message 2 of 6
(4,110 Views)
Do you have problems with:
  1. determinining the current file size
  2. switching to a new file?
  3. both.
If your LabVIEW program is the only thing that is writing to the file, you can keep track of the character count locally so you don't constantly need to check the file size. Assuming the writing occurs in a loop and you don't constantly open and close the file, keep the file reference in a shift register and add a case structure. In the normal case, wire the file reference across. In the other case add code to execute whenever the file is big enough, e.g. close the current file, open a new file with the incremented name, and wire the new reference out the back.
 
You can also get the file size info from e.g. "get position". If you use "file info", you might need to "flush" first.
 
 
0 Kudos
Message 3 of 6
(4,099 Views)

I have problems with closing the file that is written and opening a new file with the incremented name. I can't figure out how ?

My program is the only thing that is writing to the file and  the writing occurs in a loop.

HBu

0 Kudos
Message 4 of 6
(4,067 Views)
I would write my own subvi that would monitor the current file size and when it reached the preset size, it would close the file and open/create another with an incremented file name. Look in the advanced File I/O pallette for the subvis get file size, get file position, close file, open/create file.
Doug Ferguson
0 Kudos
Message 5 of 6
(4,061 Views)


@HBu wrote:
I have problems with closing the file that is written and opening a new file with the incremented name. I can't figure out how ?
Could you be a bit more specific on the exact point that gives you problems? Closing a file is a simple as connecting a "file close" function to the reference. Opening a file is equally easy. Programmatically creating a new file name is just a string operation on the file name. I would recommend to keep the filename constant lenght and reserve a fixed number of digits for the serial number, padded with leading zeroes:
 
(e.g. [MyFile00000.dat ... MyFile99999.dat] instead of  [MyFile0.dat ... MyFile99999.dat])
Message 6 of 6
(4,049 Views)