# How to insert a "variable string" into "FILENAME" topic of "FILE IN" node?

**URL:** <https://discourse.nodered.org/t/how-to-insert-a-variable-string-into-filename-topic-of-file-in-node/38672>\
**Category:** General\
**Created:** [6 January 2021 18:20 UTC](https://discourse.nodered.org/t/how-to-insert-a-variable-string-into-filename-topic-of-file-in-node/38672 "2021-01-06T18:20:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luks](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/luks/32/33365_2.png) [@luks](https://discourse.nodered.org/u/luks)\
**Post date:** [6 January 2021 18:20 UTC](https://discourse.nodered.org/t/how-to-insert-a-variable-string-into-filename-topic-of-file-in-node/38672/1 "2021-01-06T18:20:47Z")

</div>

Hello,

I'm working with a machine that uses different programms according to the production. Each programm has its own file and the machine says what programm is running thru an ".ini" file. I'm reading this .ini and getting the directory and filename of the actual programm running. Now i need to read the programm file so i can get the setup values. The filename and directory are always changing so i need it to be an "variable" string and insert it in the "FILE IN" node, but can't manage to do it.

I did this to get the names of directory and file then change it to variables.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/93097c03dd11217e35bc2d7a9e9e8ad32a02065a.png)

variables:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e996ca163cc20bd5671e5d6e930bfc88be8ac61.png)

now i need to make a complete path with the variables, like "C:\Users\user\Documents\projects\VARIABLE1\VARIABLE2" and insert it into the read file node:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/f/8fe47ff41b537911df8e8f0565899e95fbd92b9d.png)

Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 January 2021 18:33 UTC](https://discourse.nodered.org/t/how-to-insert-a-variable-string-into-filename-topic-of-file-in-node/38672/2 "2021-01-06T18:33:46Z")

</div>

You can use a change node to concatenate the string and insert the globals using JSONata expression. Or do similar in a function node with Javascript. Then feed msg.filename into the file in node.

```auto
[{"id":"4d185d09.5d09a4","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":70,"y":2620,"wires":[["b18987ec.4d8fd"]]},{"id":"b18987ec.4d8fd","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"\"C:\\\\Users\\\\user\\\\Documents\\\\projects\\\\\" & $globalContext(\"directory\") & \"\\\\\" & $globalContext(\"file\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":2660,"wires":[["fcb80581.9b311"]]},{"id":"fcb80581.9b311","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":506.33331298828125,"y":2570.333251953125,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![luks](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/luks/32/33365_2.png) [@luks](https://discourse.nodered.org/u/luks)\
**Post date:** [6 January 2021 18:59 UTC](https://discourse.nodered.org/t/how-to-insert-a-variable-string-into-filename-topic-of-file-in-node/38672/3 "2021-01-06T18:59:58Z")

</div>

Thank you very much!

---

<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:** [20 January 2021 19:00 UTC](https://discourse.nodered.org/t/how-to-insert-a-variable-string-into-filename-topic-of-file-in-node/38672/4 "2021-01-20T19:00:24Z")

</div>

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