# Recreate file after delete it

**URL:** <https://discourse.nodered.org/t/recreate-file-after-delete-it/10425>\
**Category:** General\
**Created:** [22 April 2019 10:01 UTC](https://discourse.nodered.org/t/recreate-file-after-delete-it/10425 "2019-04-22T10:01:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![hathemi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hathemi/32/3792_2.png) [@hathemi](https://discourse.nodered.org/u/hathemi)\
**Post date:** [22 April 2019 10:01 UTC](https://discourse.nodered.org/t/recreate-file-after-delete-it/10425/1 "2019-04-22T10:01:00Z")

</div>

My question might be silly, but, i was trying to recreate file after delete it with ops-delete node. I'am not sure is there a priority between nodes?? Because each time i deploy flow, it append new lines to the existing file then delete it.

 ![Sans%20titre](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f25adb10d08dc0637a18e60b9296a58905aeadd5.png)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [22 April 2019 10:06 UTC](https://discourse.nodered.org/t/recreate-file-after-delete-it/10425/2 "2019-04-22T10:06:54Z")

</div>

That sounds like the file-ops node is passing on the message before the file delete completes. I suggest you raise an issue against the node to get it fixed.

---

<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:** [22 April 2019 10:08 UTC](https://discourse.nodered.org/t/recreate-file-after-delete-it/10425/3 "2019-04-22T10:08:18Z")

</div>

its likely the file deletion is asynchronous & the node is returning a msg before its complete.

I'm not certain if that was the authors intention (might want to ask in github) but for now, you could probably hack it by adding a delay before writing.

You could possibly also use a file watcher to watch for file deletion then trigger the write operation?

**edit...**  
I thought there was a file watcher node - seems not - my bad.

---

<div class="post-metadata">

**Author:** ![hathemi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hathemi/32/3792_2.png) [@hathemi](https://discourse.nodered.org/u/hathemi)\
**Post date:** [22 April 2019 10:14 UTC](https://discourse.nodered.org/t/recreate-file-after-delete-it/10425/4 "2019-04-22T10:14:45Z")

</div>

> [@Steve-Mcl](#):
>
> file watcher

> **[node-red-contrib-wfwatch](https://flows.nodered.org/node/node-red-contrib-wfwatch)**
>
> Windows folder watch

there is a file watcher .

---

<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:** [22 April 2019 10:19 UTC](https://discourse.nodered.org/t/recreate-file-after-delete-it/10425/5 "2019-04-22T10:19:24Z")

</div>

aha knew i'd seen one in the past - well spotted.

_I searched watcher - found nothing DOH - I should know better_

---

<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:** [22 April 2019 10:20 UTC](https://discourse.nodered.org/t/recreate-file-after-delete-it/10425/6 "2019-04-22T10:20:21Z")

</div>

There is also the built in watch node - but hey....  
Also the file node can be set to overwrite a file if needed so maybe no need to delete in the first place...

---

<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:** [22 April 2019 10:20 UTC](https://discourse.nodered.org/t/recreate-file-after-delete-it/10425/7 "2019-04-22T10:20:56Z")

</div>

ah crap there is also the built in "watch" node.

I put it down to long Easter weekend 🙂

---

<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:** [22 April 2019 10:22 UTC](https://discourse.nodered.org/t/recreate-file-after-delete-it/10425/8 "2019-04-22T10:22:55Z")

</div>

> [@dceejay](#):
>
> Also the file node can be set to overwrite a file if needed so maybe no need to delete in the first place..

Very good point.

_You can probably tell i do very little with files_

---

<div class="post-metadata">

**Author:** ![hathemi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hathemi/32/3792_2.png) [@hathemi](https://discourse.nodered.org/u/hathemi)\
**Post date:** [22 April 2019 10:26 UTC](https://discourse.nodered.org/t/recreate-file-after-delete-it/10425/9 "2019-04-22T10:26:19Z")

</div>

> [@dceejay](#):
>
> overwrite a file

No, overwriting does not work with my case, because i'am adding lines to file inside a loop function. i split the msg.payload then send it to file.

---

<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:** [22 April 2019 10:44 UTC](https://discourse.nodered.org/t/recreate-file-after-delete-it/10425/10 "2019-04-22T10:44:39Z")

</div>

yes - fair enough.  
But as Nick pointed out you should raise an issue on the fs-ops node project so it can be fixed.

---

<div class="post-metadata">

**Author:** ![hathemi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hathemi/32/3792_2.png) [@hathemi](https://discourse.nodered.org/u/hathemi)\
**Post date:** [22 April 2019 10:49 UTC](https://discourse.nodered.org/t/recreate-file-after-delete-it/10425/11 "2019-04-22T10:49:18Z")

</div>

ok i'll do that.
