# Read the contents of a folder

**URL:** <https://discourse.nodered.org/t/read-the-contents-of-a-folder/694>\
**Category:** General\
**Created:** [8 June 2018 10:20 UTC](https://discourse.nodered.org/t/read-the-contents-of-a-folder/694 "2018-06-08T10:20:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThanosMel](https://avatars.discourse-cdn.com/v4/letter/t/db5fbb/32.png) [@ThanosMel](https://discourse.nodered.org/u/ThanosMel)\
**Post date:** [8 June 2018 10:20 UTC](https://discourse.nodered.org/t/read-the-contents-of-a-folder/694/1 "2018-06-08T10:20:02Z")

</div>

I have a local folder with uknown number of xml files. I want to take the xml files convert them to json and make a new folder with the json files. Is it possible with node - red. (I know how to convert xml to json)

---

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [8 June 2018 10:41 UTC](https://discourse.nodered.org/t/read-the-contents-of-a-folder/694/2 "2018-06-08T10:41:36Z")

</div>

Each json will be a independent plan text if is the case you will have to writte a function to automatically create a different output file name for each one, set this as msg.filename and the json as payload and then pull this into a file writte node

---

<div class="post-metadata">

**Author:** ![ThanosMel](https://avatars.discourse-cdn.com/v4/letter/t/db5fbb/32.png) [@ThanosMel](https://discourse.nodered.org/u/ThanosMel)\
**Post date:** [8 June 2018 10:52 UTC](https://discourse.nodered.org/t/read-the-contents-of-a-folder/694/3 "2018-06-08T10:52:28Z")

</div>

I did that and it worked .But how can i send an http post request and post all the created json files to a http endpoint.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [8 June 2018 10:56 UTC](https://discourse.nodered.org/t/read-the-contents-of-a-folder/694/4 "2018-06-08T10:56:07Z")

</div>

Take a look at the http request node

---

<div class="post-metadata">

**Author:** ![ThanosMel](https://avatars.discourse-cdn.com/v4/letter/t/db5fbb/32.png) [@ThanosMel](https://discourse.nodered.org/u/ThanosMel)\
**Post date:** [8 June 2018 10:57 UTC](https://discourse.nodered.org/t/read-the-contents-of-a-folder/694/5 "2018-06-08T10:57:32Z")

</div>

can the http request payload be multiple json files?

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [8 June 2018 11:04 UTC](https://discourse.nodered.org/t/read-the-contents-of-a-folder/694/6 "2018-06-08T11:04:51Z")

</div>

If you are loading the files into Node-RED to convert from xml to JSON the flow handles each flow separately, which is what I thought you were doing.

Otherwise look on [flows.nodered.org](http://flows.nodered.org) for nodes that can handle multiple files

---

<div class="post-metadata">

**Author:** ![ThanosMel](https://avatars.discourse-cdn.com/v4/letter/t/db5fbb/32.png) [@ThanosMel](https://discourse.nodered.org/u/ThanosMel)\
**Post date:** [8 June 2018 16:29 UTC](https://discourse.nodered.org/t/read-the-contents-of-a-folder/694/7 "2018-06-08T16:29:50Z")

</div>

I found the solution using the node-red-contrib-fs-ops and node-node-red-contrib-fullsplitter. For those of you that have the same question just use the fs-ops-dir node to get the array of all the files contained in the folder and then use the fullsplitter node. The flow is not functional of course just use your own paths and type your code in the “give file path” function.

````auto
```[{"id":"4d82c25e.1e4b3c","type":"fs-ops-dir","z":"ca4f9243.31a82","name":"JSON Folder","path":"C:\\Users\\a.melandinos\\Documents\\JSONfiles","pathType":"str","filter":"*","filterType":"str","dir":"files","dirType":"msg","x":306.88671112060547,"y":154.55859661102295,"wires":[["63fedd7b.9d56a4"]]},{"id":"778b18c5.f71288","type":"switch","z":"ca4f9243.31a82","name":"","property":"files","propertyType":"msg","rules":[{"t":"null"}],"checkall":"true","repair":false,"outputs":1,"x":532.8828926086426,"y":297.24225521087646,"wires":[["63fedd7b.9d56a4"]]},{"id":"991545d3.ac8778","type":"file in","z":"ca4f9243.31a82","name":"File to be posted","filename":"","format":"utf8","chunk":false,"sendError":false,"x":882.51953125,"y":62.69533157348633,"wires":[["c0c05a36.a5ed38"]]},{"id":"4d0d5aa1.a10aa4","type":"function","z":"ca4f9243.31a82","name":"give file path","func":"//Create the name of the file we need to retrieve in order to POST it\n//later.\nvar filepath =\"C:/Users/a.melandinos/Documents/JSONfiles/\";\nvar prefix = msg.array;\nvar prefixFinal = JSON.stringify(prefix);\n\nprefixFinal=prefixFinal.substr(1).slice(0, -1);\n\nvar finalPath = filepath.concat(prefixFinal);\n\nfinalPath.replace(\"/\",\"\\ \");\nmsg.filename = finalPath;\n\nreturn msg;","outputs":1,"noerr":0,"x":739.5118560791016,"y":165.79689598083496,"wires":[["991545d3.ac8778"]]},{"id":"dd92c82e.c68d68","type":"comment","z":"ca4f9243.31a82","name":"Looping in the folder till no file left.","info":"This node takes an array as an input and passes\neach element of the array individually as an output.\n\nThe output is the name of the file.\nFor example \"file1.json\" .","x":539.8907012939453,"y":122.59766006469727,"wires":[]},{"id":"63fedd7b.9d56a4","type":"fullsplitter","z":"ca4f9243.31a82","name":"Split json files","property":"files","x":527.8984909057617,"y":168.94145011901855,"wires":[["4d0d5aa1.a10aa4"],["778b18c5.f71288"]]}]```

````

---

<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:** [8 June 2018 18:09 UTC](https://discourse.nodered.org/t/read-the-contents-of-a-folder/694/8 "2018-06-08T18:09:26Z")

</div>

Use three backticks before and after code snippets to format correctly so they ca be imported directly into Node-RED. Thanks

---

<div class="post-metadata">

**Author:** ![ThanosMel](https://avatars.discourse-cdn.com/v4/letter/t/db5fbb/32.png) [@ThanosMel](https://discourse.nodered.org/u/ThanosMel)\
**Post date:** [8 June 2018 19:01 UTC](https://discourse.nodered.org/t/read-the-contents-of-a-folder/694/9 "2018-06-08T19:01:35Z")

</div>

i am new didnt know that thanks for the advice sir

---

<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:** [8 June 2018 19:06 UTC](https://discourse.nodered.org/t/read-the-contents-of-a-folder/694/10 "2018-06-08T19:06:09Z")

</div>

… and you can edit your old posts to add them if you like 😉

---

<div class="post-metadata">

**Author:** ![faisal-saddique](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/faisal-saddique/32/70487_2.png) [@faisal-saddique](https://discourse.nodered.org/u/faisal-saddique)\
**Post date:** [27 December 2022 07:38 UTC](https://discourse.nodered.org/t/read-the-contents-of-a-folder/694/11 "2022-12-27T07:38:55Z")

</div>

Thanks for the flow!

---

<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:** [27 December 2022 09:44 UTC](https://discourse.nodered.org/t/read-the-contents-of-a-folder/694/12 "2022-12-27T09:44:37Z")

</div>


