Showing results for 
Search instead for 
Did you mean: 

how to open 40 text files and save to a single spreadsheet

I have folders each with 40 text files, 20 ending in "charac.txt" and 20 ending in "verify.txt". I can use the LIST function to read the contents of the folder and separate the file names into two 1D arrays of strings, but then I can't figure out how to open each file in turn and save the contents into a single spreadsheet. I have a vi that has me open each file manually and append it to the same spreadsheet, but I want to automate the opening and saving of the files. I have seen a similair example done with arrays and numbers, but I am new to Labview and having an awful time with the whole ARRAY concept, and need to save the numbers as strings.

Any help would be appreciated!

0 Kudos
Message 1 of 7
Since you've been able to get the list of files into a couple of string arrays, that is a good start.
Feed those arrays into a for loop and make sure auto-indexing of those arrays is turned on at the left edge of the loop structure.
Use functions such as string to path and build path to turn that data into a file path.  That can be fed into the read file VI's.  The data can be fed into a write file VI which has a path you defined for the new file.  (Don't forget to append the data rather than overwrite.)  Which file VI's are correct for you you will have to figure out.  It could be read/write text files.  Or read/write spreadsheet files.

Message Edited by Ravens Fan on 05-17-2007 11:31 PM

Message 2 of 7
Basically, use the same process you would use when doing it manually. Are you wanting to simply append the file contents or add additional columns to the rows that are already there? The first is the easiest. Simply read the first file and write it to the destination with the overwrite input set to TRUE. Now open each of the other files in order and write their contents to the destination file but with the overwrite input set to FALSE. If you need to do the second, write back because it takes a little longer to explain...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 3 of 7
Ok, I give up. I've posted the vi and a folder I'd like the data to be read from.

What I want is the text files to be opened one after the other and appended to a spreadsheet. I can't use numbers because I need to keep the AM PM data, so I am using strings.

The vi works if you delete the stuff outside the loop and the loop itself and in place of the file path into the 'read from spreadsheet strings' subvi have a blank.

What simple thing am I missing here?


Message Edited by slipstick on 05-18-2007 09:16 PM

Message Edited by slipstick on 05-18-2007 09:17 PM

Download All
0 Kudos
Message 4 of 7
I couldn't run your VI because I didn't have the read and write to spreadsheet file strings VI's   (Are these some special VI's you created?)
I figured the problem is probably in how the paths are getting built, so I deleted those VI's and just put up some indicators to see what paths are getting built.  Here is what I found
The bottom wire out of the list function provides an array of folders.  This is a list of folders that matches your search pattern.  Of which there are none.  So it is empty.  If it wasn't empty but add multiple elements.  All of those elements would get concatenated together once the whole array got passed into the for loop.
Kill that lower wire coming out of folder names completely.  Wire the path to search control into the loop.  Feed that into a Build Path (file I/O palette).  Then the path that comes out of that can be fed into the read and write file VI's.
See the attached screenshot.
I would also recommend making the browse button visible on your path to search control.


Message Edited by Ravens Fan on 05-19-2007 12:14 AM

Message 5 of 7
You are a steely eyed missile man, as the saying goes!

That worked a treat! This will save me literally 400 mouse clicks on Monday!

I am learning LabVIEW and was trying to emulate a similair application we have, which I now see could be done a whole lot better!

0 Kudos
Message 6 of 7
The 'write to spreadsheet file strings' VI's are simply the 'write to spreadsheet file' vi's configured to accept strings instead of numbers.

0 Kudos
Message 7 of 7