LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Clear txt file

Solved!
Go to solution

Hi All !

I write some data to a file, but before i do it i want to clear the file from previous content.

Surprisingly i didn't find any control/function to do the operation.

I'm using LV 7.1.

0 Kudos
Message 1 of 7
(3,209 Views)
Solution
Accepted by john7

Hi John,

 

ever tried to "create or replace" a file instead of "open or create"?

There also exists a "Delete File" function, in case you don't trust the file open function and their options...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 7
(3,197 Views)

Since you have the Path to the file you want to replace in the 'WRITE' case you coud use the 'Delete.vi. in 'Advance File Functions' Bottom right in the FILE I/O section of the Programming pallette.

 

 

0 Kudos
Message 3 of 7
(3,191 Views)

Create or replace option pops-up a dialog. Delete is an option, also in C/C#  it's quite a simple operation to clear a file.

0 Kudos
Message 4 of 7
(3,187 Views)

It's OK! There is a flag to suppress pop-up dialog. Thanks a lot!

0 Kudos
Message 5 of 7
(3,184 Views)

Hi John,

 

"Delete is an option, also in C/C#  it's quite a simple operation to clear a file."

Either use the Delete function or try the SetFileSize/SetFilePosition functions...

 

How would you do that in C/C++/C# anyway?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 7
(3,181 Views)

"How would you do that in C/C++/C# anyway?"

 

It's library functions but I think on a low level it goes like this (it's pseudo code):

while(!EOF)

{

   clear(or replase) char at position;

    increment position;

}

 

 

0 Kudos
Message 7 of 7
(3,177 Views)