03-15-2010 09:11 AM
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
03-15-2010 09:23 AM - edited 03-15-2010 09:23 AM
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.
03-15-2010 09:23 AM
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
03-15-2010 09:36 AM
You want to use a 'for loop' and the function called 'List Folders'.
03-15-2010 09:46 AM
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
03-15-2010 12:14 PM
Phillip,
I tried recreating this .vi and it doesn't fill the text file that i establish.
03-15-2010 12:18 PM