02-20-2016 11:47 AM
Hi all,
I need to add some (text) data to specific locations of an existing text file template and then rename the newly written file.
and END_TABLE_C1 in the template file.
Like this ...
# Optional section
START_TABLE_C2
END_TABLE_C2
# Optional section
START_TABLE_C3
END_TABLE_C3
# Optional section
START_TABLE_C4
END_TABLE_C4
START_TABLE_C5
END_TABLE_C5
# Optional section
START_TABLE_C6
END_TABLE_C6
# Optional section
START_TABLE_C7
END_TABLE_C7
# Optional section
START_TABLE_C8
END_TABLE_C8
--------------------------------------------
So, the way I approached this is to read the template file and 8 data files into 9 arrays, then I insert each text file data (array) to specific location of the template array by it’s index number.
But this is not good enough because the data text data files can vary from file to file and I don’t always have the same number of lines in the (data) text files.
Aditionally, I have file path controls (9 of them) to find the text files and write to the template.
I like to be able to just enter the serial number of the file, create the path to the data file and find it in the folder.
Appreciate your help, Thanks.
Solved! Go to Solution.
02-20-2016 12:18 PM
02-20-2016 12:36 PM
are you sure that will work?
as I said, I want to insert/write in between the START and END tags
Set File Position Function only gives me start, end and current positions.
02-20-2016 01:22 PM
I would use Read Text File.vi instead of Read Spreadsheet File.vi Right click the function and select "read lines" and then set the count input to -1. The output will be a 1D arrary of the file lines. Then use Search 1D Array to get the index of START_TABLE_Cx (add 1 to the index to add after. Finally use Write To Text File to write to the new file.
Ben64
02-20-2016 01:56 PM
Sorry i got what is your means now
I think ben give the method to do
also this method maybe work
just before start select your
main file= temp
your first data
and place and name for new file
02-20-2016 02:38 PM
Hi,
Ben, Thanks, it works for one data file insertion into template but I tried doeing it for multiple data file insertion and didint work for me, it overwrites the sections.
I am attching the rsult file also
Hatef, Thanks, I keep getting duplicate file path error running the vi,
02-20-2016 02:54 PM
alex75 a écrit :Hi,
Ben, Thanks, it works for one data file insertion into template but I tried doeing it for multiple data file insertion and didint work for me, it overwrites the sections.
I am attching the rsult file also
Hatef, Thanks, I keep getting duplicate file path error running the vi,
You need to do the new insertion in the previously modified array.
Ben64
02-20-2016 03:05 PM
OK I just make a little change to fix that problem to
the method is same
if you find more problem So just try fix problems to use
there are not serious problem
02-20-2016 04:33 PM
Here is a more compact and efficient way to do it. You could eventually replace the path array input section with the Recursive File List VI. (from the File I/O - Advanced File Functions palette, have a look at the help file, you can search for a pattern in the filename and it returns an array of the file found paths).
Ben64
02-21-2016 04:21 AM
Hi Ben, Thanks, it works fine.
I also modified/added to it, so that instead of file path , serial number of data files will be entered/read from operators input , and data file will be found in the folder to be read and pasted to the template.
now I need some safeguard that if the file is not found in the folder (like if operator enters a wrong serial number) what the program will decide, retry searching for file, continue , or stop?
also I need to use an event structure to start the test when all the string controls are inputted.
Thanks
Hi Hatef... I got the program running without an error, but it doesn't wite to the new file yet. anyways I got the answer for the first problem I had, thanks again.