LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Open and append text file

Hello Everyone,

 

I have been spinning my wheels with this one for a bit now.

 

I have text files in a directory.  The text files are labeled "1.txt", "2.txt", etc.  I want to create a .vi that starts by opening "1.txt", reads the lines, and appends the read lines to a new file.  After it reads all of the lines, I would like it to move on to "2.txt", read the lines, and append them to the same data file from which "1.txt"'s data went into.

 

I appreciate any help you can give.

 

Thanks 

0 Kudos
Message 1 of 7
(3,642 Views)

What have you tried? The Help on the Write to Text File function indicates that if you wire in a refnum instead of a path then file writing will occur at the current file position. Thus, if you do something like this:

 

then the contents of 2.txt will be appended.

Message Edited by smercurio_fc on 03-15-2010 09:23 AM
0 Kudos
Message 2 of 7
(3,634 Views)

You already answered much of your question on your own. You at least gave a quite detailed explanation of what your software should do step by step.

So, the only thing left to do for you is to identify the appropriate functions. I hope that the most important filefunctions are already known to you (open/read/write/close).

You can follow two approaches from here:

a) You open up the new file outside of the loop which is opening/reading the txt-files and you simply write the data into the new file in each iteration.

b) You open the new file each iteration but then you have to move the file-write pointer to the end of the file. You can use the function Set File Position in the advanced palette in order to set the pointer for writing to the file to the end of the file (Bytes: 0, from: End). Maybe you have to set the Byte to 1 if you are working with EOF.....

 

hope this helps,

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 7
(3,632 Views)

You want to use a 'for loop' and the function called 'List Folders'.

 

concat txt files.png

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

Phillip,

 

you should change the file reference tunnels to a shiftregister in order to prevent unwanted errors if the folder does not include any txt-files....

 

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 5 of 7
(3,609 Views)

Phillip, 

I tried recreating this .vi and it doesn't fill the text file that i establish.

0 Kudos
Message 6 of 7
(3,587 Views)
Fixed it, thank you for the help.
0 Kudos
Message 7 of 7
(3,586 Views)