LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read multiple files in folder and append data to one file

Solved!
Go to solution

Hi everyone,

 

I have multiple text files (couple of hundred) in a folder. I want to combine the data of the files into one file. It should obviously start at the oldest file and sequentially read the files to latest modified and append all the data to a new txt file.

 

Below is typical comma seperated data of two consecutive files:

 

2009-02-17,23:17:04,00ff,ffff,ff1c,0093,0000,0100,0001,d3ae,0cce,0cd4,0cd4,00c2,000a,09e4,0609,0000,0000,17c7
2009-02-17,23:17:06,00ff,ffff,ff1c,0093,0000,0100,0001,d3af,0cd5,0cd7,0ccf,00c2,000e,09e6,0608,0003,0000,17c7
2009-02-17,23:17:09,00ff,ffff,ff1c,0093,0000,0100,0001,d3b0,0cd2,0cd1,0cd5,00bb,000a,09f1,0608,0000,0000,17c7
2009-02-17,23:17:11,00ff,ffff,ff1c,0093,0000,0100,0001,d3b1,0c21,0ccf,0cd3,00c2,000a,09e3,0608,0000,0000,17c7
2009-02-17,23:17:14,00ff,ffff,ff1c,0093,0000,0100,0001,d3b2,0cc9,0cd5,0cd7,00c4,0008,09e4,0608,0000,0002,17c8
2009-02-17,23:17:16,00ff,ffff,ff1c,0093,0000,0100,0001,d3b3,0cd2,0cd6,0cd7,00bf,000d,09eb,0608,0000,0000,17c8
2009-02-17,23:17:19,00ff,ffff,ff1c,0093,0000,0100,0001,d3b4,0cc9,0cd8,0cd2,00c2,0009,09ea,0608,0000,0000,17c8
2009-02-17,23:17:21,00ff,ffff,ff1c,0093,0000,0100,0001,d3b5,0cd2,0cd1,0cd1,00c2,0009,09e8,0608,0000,0001,17c8

 

2009-02-17,23:17:24,00ff,ffff,ff1c,0093,0000,0100,0001,d3b6,0cd3,0cd3,0cd3,00ca,000a,09eb,0608,0001,0001,17c9
2009-02-17,23:17:26,00ff,ffff,ff1c,0093,0000,0100,0001,d3b7,0ccd,0cd8,0cd4,00bc,0006,09e6,0608,0001,0003,17c8
2009-02-17,23:17:29,00ff,ffff,ff1c,0093,0000,0100,0001,d3b8,0cd2,0cd3,0cd3,00c6,000a,09e9,0608,0001,0001,17c9
2009-02-17,23:17:31,00ff,ffff,ff1c,0093,0000,0100,0001,d3b9,0ccf,0cd3,0cd4,00ba,000a,09e8,0608,0000,0000,17c8
2009-02-17,23:17:34,00ff,ffff,ff1c,0093,0000,0100,0001,d3ba,0c1b,0cd3,0cd4,00c0,0009,09e9,0607,0001,0000,17c8
2009-02-17,23:17:36,00ff,ffff,ff1c,0093,0000,0100,0001,d3bb,0cd3,0cd4,0cd3,00c2,000a,09e8,0607,0001,0003,17c9
2009-02-17,23:17:39,00ff,ffff,ff1c,0093,0000,0100,0001,d3bc,0cd4,0cd4,0cd2,00b5,000a,09e9,0607,0001,0002,17c9
2009-02-17,23:17:41,00ff,ffff,ff1c,0093,0000,0100,0001,d3bd,0cbd,0cd4,0cd7,00c2,0009,09e8,0607,0001,0001,17c9
 

The text files have no headers just the raw data as seen above.

 

Would really appreciate any help. Thank you in advance.

 

Regards

Dan

0 Kudos
Message 1 of 22
(11,345 Views)
Solution
Accepted by topic author _Dan

Hi Dan,

 

   I dont know which version of LabVIEW u using,I attached the vi in the v 8.5. My vi sorts the file names in alphabetical order use get file info vi to sort it as u mentioned Smiley Happy

Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
Message 2 of 22
(11,340 Views)

Hi Baji,

 

Brilliant, thank you for the quick response!  Works perfectly!

 

Regards

Dan

 

 

Message 3 of 22
(11,327 Views)
I have 8.2. Any chance you can share how you did this? Thank you.
0 Kudos
Message 4 of 22
(11,151 Views)

Here is the file saved for 8.2. 

 

-Christina

 

Message 5 of 22
(11,124 Views)
One more question. I would like to transpose each text file before it is saved to the 'master' file with the Concatenate files vi. I know can be done with a Write to Spreadsheet vi, but it doesn't appear it can be done with a Write to Text. Any help would be appreciated.
0 Kudos
Message 6 of 22
(11,115 Views)

The transpose option will be available in both(read & write spread sheet).It will not available for read and write file.U can reverse the spread string using Reverse string function available at programming>>String>>Aditional string functions>>Reverse string,so before writing the file reverse the string and write to the file.

U can only do traspose to an array,u cant do for spreadsheet string.

Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
Message 7 of 22
(11,063 Views)

In order to do this with the text file read and write functions, you will have to convert the output string to an array, transpose the array, and then convert it back to a string.  The conversions can be done using the Spreadsheet String to Array and Array to Spreadsheet String VIs. 

 

-Christina

0 Kudos
Message 8 of 22
(11,023 Views)

Hi There,

I am having similar problem. I have multiple files with three column and 1000 rows. I need to open multiple file like that, copy third column from each file and write all these column in single file. I am comparatively new with labview and i use 8.2 on my mac but i have access to windows version also if needed. 

Thanks for the help

Yogesh 

0 Kudos
Message 9 of 22
(10,936 Views)
Ya its similar,I modified the code for ur need.the vis are in LV 8.5
Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
Message 10 of 22
(10,929 Views)