# Reading a text file and creating tags

**URL:** <https://forum.inductiveautomation.com/t/reading-a-text-file-and-creating-tags/25373>\
**Category:** Ignition\
**Created:** [May 28, 2019, 6:07pm UTC](https://forum.inductiveautomation.com/t/reading-a-text-file-and-creating-tags/25373 "2019-05-28T18:07:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![temesgentg2017](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@temesgentg2017](https://forum.inductiveautomation.com/u/temesgentg2017)\
**Post date:** [May 28, 2019, 6:07pm UTC](https://forum.inductiveautomation.com/t/reading-a-text-file-and-creating-tags/25373/1 "2019-05-28T18:07:34Z")

</div>

Hey All,  
I am trying to read a text file and create tags for each output that is written on the text file. The problem I am having now is, I am just able to grab the entire file. I want to grab specific out values ( string or int) and convert that to a tag. Also want to have it in a loop that way it kinda reads updated data continuously. Please Help!

I created a button and this is my script so far:

path = system.file.openFile(’.txt’)  
if path != None:  
contents = system.file.readFileAsString(path)  
system.tag.writeToTag(“WriteTags/write”, contents) event.source.parent.getComponent(“Text Area”).text = contents

---

<div class="post-metadata">

**Author:** ![Jonathan\_Geva](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Jonathan\_Geva](https://forum.inductiveautomation.com/u/Jonathan_Geva)\
**Post date:** [January 26, 2023, 1:07pm UTC](https://forum.inductiveautomation.com/t/reading-a-text-file-and-creating-tags/25373/2 "2023-01-26T13:07:27Z")

</div>

Hello,

I am attempting to do the same process you are going for here. Did you make any headway on grabbing specific contents from the text file?

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [January 26, 2023, 1:13pm UTC](https://forum.inductiveautomation.com/t/reading-a-text-file-and-creating-tags/25373/3 "2023-01-26T13:13:56Z")

</div>

Welcome!

You want to read each line and split it if it has a CSV separator

Here is an example

```auto
if os.listdir(filepath):
				
				with open(os.path.join(filepath,file_xtn),'r'):
				
					first_line_ignore = file.readline()
					#print len(file)
					for line in file.readlines():
						data = line.split(";")
						yearX = line.find(year) 
						(month_str,day_str
						,) = map(lambda x,y:line[yearX+x:yearX+y],((-3,-1,),(-6,4,),))
						datetimef = '{0}-{1}-{2} {3}'.format(year,month_str,day_str,data[1])
						date_str = datetimef[:10]
						system.db.runSFPrepUpdate("INSERT INTO rapid_raw_rest (date_time, batch, colour, profile_code, length, rapid) VALUES (?, ?, ?, ?, ?, ?)", [datetimef, data[2], data[3], data[4], data[5], rapid], ["Xeon"])

```

Think the formatting skewed slightly on copy paste to forum, it should be 1 tab indent per section after a colon

---

<div class="post-metadata">

**Author:** ![chandrasekar\_s](https://avatars.discourse-cdn.com/v4/letter/c/8baadc/32.png) [@chandrasekar\_s](https://forum.inductiveautomation.com/u/chandrasekar_s)\
**Post date:** [February 27, 2024, 1:22pm UTC](https://forum.inductiveautomation.com/t/reading-a-text-file-and-creating-tags/25373/4 "2024-02-27T13:22:49Z")

</div>

Hi temes,

Is that split concept working with code?

---

<div class="post-metadata">

**Author:** ![chandrasekar\_s](https://avatars.discourse-cdn.com/v4/letter/c/8baadc/32.png) [@chandrasekar\_s](https://forum.inductiveautomation.com/u/chandrasekar_s)\
**Post date:** [February 28, 2024, 5:45am UTC](https://forum.inductiveautomation.com/t/reading-a-text-file-and-creating-tags/25373/6 "2024-02-28T05:45:47Z")

</div>

Log files.
