# Moving file only when finished

**URL:** <https://discourse.nodered.org/t/moving-file-only-when-finished/57667>\
**Category:** General\
**Created:** [2 February 2022 15:58 UTC](https://discourse.nodered.org/t/moving-file-only-when-finished/57667 "2022-02-02T15:58:28Z")\
**Posts on this page:** 7\
**Page:** 2

<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:** [3 February 2022 15:36 UTC](https://discourse.nodered.org/t/moving-file-only-when-finished/57667/21 "2022-02-03T15:36:37Z")

</div>

> [@krambriw](#):
>
> I use the following code to loop through a directory, check if the file is open or not before moving it

I do exactly the same thing, and is what I suggested at the start, and it is a better solution. There is no problem doing that in node red, the problem is how to tell if a file is open in Windows, which I don't know how to do.

---

<div class="post-metadata">

**Author:** ![Broewn4PS](https://avatars.discourse-cdn.com/v4/letter/b/bc79bd/32.png) [@Broewn4PS](https://discourse.nodered.org/u/Broewn4PS)\
**Post date:** [3 February 2022 15:37 UTC](https://discourse.nodered.org/t/moving-file-only-when-finished/57667/22 "2022-02-03T15:37:32Z")

</div>

Once the move is complete it triggers the watch node again which results in an error because the file already moved, that's all. Clutter in the debug screen

---

<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:** [3 February 2022 16:04 UTC](https://discourse.nodered.org/t/moving-file-only-when-finished/57667/23 "2022-02-03T16:04:29Z")

</div>

What message do you get from the watch node when the file is deleted?

**[Edit]** Set the debug node to Output Complete Message so we can see everything.

---

<div class="post-metadata">

**Author:** ![Broewn4PS](https://avatars.discourse-cdn.com/v4/letter/b/bc79bd/32.png) [@Broewn4PS](https://discourse.nodered.org/u/Broewn4PS)\
**Post date:** [3 February 2022 16:08 UTC](https://discourse.nodered.org/t/moving-file-only-when-finished/57667/24 "2022-02-03T16:08:33Z")

</div>

A file triggers the watch node twice, once arriving once leaving. After the second trigger it errors on the move node.

```auto
no such file or directory

```

---

<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:** [3 February 2022 16:13 UTC](https://discourse.nodered.org/t/moving-file-only-when-finished/57667/25 "2022-02-03T16:13:14Z")

</div>

Sorry, you probably didn't see my previous post, it may have crossed with yours. Feed the output of the watch node into a debug node set to Output complete message and show us what it shows for the first and second trigger. You can paste a screenshot here.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [3 February 2022 16:25 UTC](https://discourse.nodered.org/t/moving-file-only-when-finished/57667/26 "2022-02-03T16:25:55Z")

</div>

Following a Python way of solving it, if of interest, is described here

> <https://stackoverflow.com/questions/11114492/check-if-a-file-is-not-open-nor-being-used-by-another-process>

---

<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:** [4 April 2022 16:26 UTC](https://discourse.nodered.org/t/moving-file-only-when-finished/57667/27 "2022-04-04T16:26:02Z")

</div>

Closed on 4 April 2022 16:26 UTC

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

[Previous page](https://discourse.nodered.org/t/moving-file-only-when-finished/57667.md?page=1)
