# Delete Files in a specific folder after 30 days

**URL:** https://discourse.nodered.org/t/delete-files-in-a-specific-folder-after-30-days/37598
**Category:** General
**Created:** [16 December 2020 21:29 UTC](https://discourse.nodered.org/t/delete-files-in-a-specific-folder-after-30-days/37598 "2020-12-16T21:29:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![node1](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@node1](https://discourse.nodered.org/u/node1)
#### Post date: [16 December 2020 21:29 UTC](https://discourse.nodered.org/t/delete-files-in-a-specific-folder-after-30-days/37598/1 "2020-12-16T21:29:03Z")

</div>

Hello,

I just want to create a simple flow, where files in a specify folder on my laptop will be deleted if those are older than 30 days.

Could someone give me an example please?

Thanks in regards!

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [16 December 2020 21:34 UTC](https://discourse.nodered.org/t/delete-files-in-a-specific-folder-after-30-days/37598/2 "2020-12-16T21:34:46Z")

</div>

First thing to do would be to get a list of files in that folder, along with their file details, into a flow. So I would start by looking at the flows site for a Node that will help.

---

<div class="post-metadata">

### Author: ![node1](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@node1](https://discourse.nodered.org/u/node1)
#### Post date: [16 December 2020 21:51 UTC](https://discourse.nodered.org/t/delete-files-in-a-specific-folder-after-30-days/37598/4 "2020-12-16T21:51:20Z")

</div>

[{"id":"f4d0c5b8.b12428","type":"function","z":"828946d6.27bde","name":"Set filename","func":"//Path where to save your csv\nlet path = "/Users/thyle/Desktop/";\n\n// Get the current time and convert it to text\nlet now = new Date();\nlet yyyy = now.getFullYear();\nlet mm = now.getMonth() \< 9 ? "0" + (now.getMonth() + 1) : (now.getMonth() + 1); // getMonth() is zero-based\nlet dd = now.getDate() \< 10 ? "0" + now.getDate() : now.getDate();\nlet hh = now.getHours() \< 10 ? "0" + now.getHours() : now.getHours();\nlet mmm = now.getMinutes() \< 10 ? "0" + now.getMinutes() : now.getMinutes();\nlet ss = now.getSeconds() \< 10 ? "0" + now.getSeconds() : now.getSeconds();\n\n//Get the sourceName \n//let sourceName = msg.filecontentWithHeader[0][1];\nlet sourceName = "CSV\_File";\n\n//Set the filenname\nmsg.fname = sourceName + "_" + yyyy + "_"+ mm +"\_"+ dd + ".csv";\nmsg.filename = path + msg.fname;\n\n\n// We are passing the file name search pattern to fs node to tell us if the file exists or not\nmsg.payload = {"pattern":msg.fname};\n\nnode.status({fill:"blue",shape:"ring",text:msg.fname});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":360,"wires":[["26a5109.eda207","fc2884bb.6a782"]]}]

---

<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: [16 December 2020 23:57 UTC](https://discourse.nodered.org/t/delete-files-in-a-specific-folder-after-30-days/37598/5 "2020-12-16T23:57:23Z")

</div>

[This thread](https://discourse.nodered.org/t/rotating-files-for-saving-snapshots/37189/9) was very similar & should work with a small tweak.

---

<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: [14 February 2021 23:57 UTC](https://discourse.nodered.org/t/delete-files-in-a-specific-folder-after-30-days/37598/6 "2021-02-14T23:57:24Z")

</div>

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