# Read a txt file without write protection

**URL:** https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580
**Category:** General
**Created:** [26 November 2020 18:22 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580 "2020-11-26T18:22:22Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![YT2310](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yt2310/32/35255_2.png) [@YT2310](https://discourse.nodered.org/u/YT2310)
#### Post date: [26 November 2020 18:22 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/1 "2020-11-26T18:22:23Z")

</div>

Hey there,

I try to read a file in Node Red every second. The file is written from a program every 0.2 seconds.  
Now the file sometimes changes the length of the array:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/50a5775a68172f7df76208079b2b54ab64a5d804.png)  
This is in a way impossible cause the program writes always a new line into the txt file.

I now suspect that this happens when the program writes the file and node red has opened it for reading.  
Has anyone had experience with something like this and can help me?

Thank you for your help!

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [26 November 2020 19:07 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/2 "2020-11-26T19:07:42Z")

</div>

normally you would something like the tail node to just monitor things being added to a file.  
writing it so often and reading it is generally a bad idea for the reasons you are finding.  
But some operating systems cope better than others.

---

<div class="post-metadata">

### Author: ![YT2310](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yt2310/32/35255_2.png) [@YT2310](https://discourse.nodered.org/u/YT2310)
#### Post date: [26 November 2020 19:45 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/3 "2020-11-26T19:45:11Z")

</div>

I totally agree with you, but my problem is, that the filename change after few minutes..

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [26 November 2020 21:58 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/4 "2020-11-26T21:58:37Z")

</div>

I don't understand what you mean by that. Please provide more details of exactly what is going on. Then we may be able to suggest a solution.

---

<div class="post-metadata">

### Author: ![YT2310](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yt2310/32/35255_2.png) [@YT2310](https://discourse.nodered.org/u/YT2310)
#### Post date: [27 November 2020 12:16 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/5 "2020-11-27T12:16:04Z")

</div>

the tail node it self works well, but with the tail node I am just able to read the new line?  
For my application I need the hole file because I show it in a grid

---

<div class="post-metadata">

### Author: ![YT2310](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yt2310/32/35255_2.png) [@YT2310](https://discourse.nodered.org/u/YT2310)
#### Post date: [27 November 2020 13:35 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/6 "2020-11-27T13:35:20Z")

</div>

I think the easiest way would be if I just copie the file without reading it.  
Is that possible?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 November 2020 15:46 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/7 "2020-11-27T15:46:11Z")

</div>

You have not answered the question that I asked earlier. What exactly do you want to achieve.

---

<div class="post-metadata">

### Author: ![YT2310](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yt2310/32/35255_2.png) [@YT2310](https://discourse.nodered.org/u/YT2310)
#### Post date: [3 December 2020 16:26 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/8 "2020-12-03T16:26:29Z")

</div>

sorry, my PLC write every 0.2s some different data in a new line into a file. I want to show the data on the dashboard.  
I have now tried different ways of doing this.  
The one that I think works best is when I look at the file with a tail node to get the last line that was added.  
This works fine, but I can't encode the utf le 16 string to display numbers correctly.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [3 December 2020 16:34 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/9 "2020-12-03T16:34:18Z")

</div>

> [@YT2310](#):
>
> my PLC write every 0.2s some different data in a new line into a file

Please answer all questions - there may be a simple solution you are missing...

What make and model of PLC?

Where does PLC write this file? Inside the PLc file system?

How do you access this file?

---

<div class="post-metadata">

### Author: ![YT2310](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yt2310/32/35255_2.png) [@YT2310](https://discourse.nodered.org/u/YT2310)
#### Post date: [4 December 2020 07:28 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/10 "2020-12-04T07:28:16Z")

</div>

The plc is a Siemens 1500  
But the plc correspondent with a pc via network and writes a .mcv data file on the pc.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [4 December 2020 07:36 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/11 "2020-12-04T07:36:33Z")

</div>

So, the PLC does not write a file, a PC connected to the PLC and that PC reads PLC data then writes the file.

What program is writing this file? Wincc? Custom application? Node-red?

As it is a relatively new PLC and there are several nodes available, why don't you simply request the values from the PLC instead of messing around with files?

---

<div class="post-metadata">

### Author: ![YT2310](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yt2310/32/35255_2.png) [@YT2310](https://discourse.nodered.org/u/YT2310)
#### Post date: [4 December 2020 07:42 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/12 "2020-12-04T07:42:21Z")

</div>

Its a custom application. The file is used for some other stuff, so I don t want to change the why this is running (cause this runs since a while). I don't want to change this communication. I am looking for a simple solution how I can access the data with node red without further changes or further communication to the PLC.  
As I said, the tail node works very well, except for the fact that I get the data UTF-LE16 encoded and therefore cannot change the string to a number.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [5 December 2020 10:23 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/13 "2020-12-05T10:23:49Z")

</div>

Feed the data into a debug node and show us what it displays so we can better understand what you have.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [5 December 2020 10:43 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/14 "2020-12-05T10:43:49Z")

</div>

If you can get the binary direct then you could decode it like this maybe [https://stackoverflow.com/questions/40418384/node-encode-and-decode-utf-16-buffer](https://stackoverflow.com/questions/40418384/node-encode-and-decode-utf-16-buffer)

---

<div class="post-metadata">

### Author: ![YT2310](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yt2310/32/35255_2.png) [@YT2310](https://discourse.nodered.org/u/YT2310)
#### Post date: [7 December 2020 11:38 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/15 "2020-12-07T11:38:56Z")

</div>

thank you that works!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [21 December 2020 11:39 UTC](https://discourse.nodered.org/t/read-a-txt-file-without-write-protection/36580/16 "2020-12-21T11:39:01Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
