# How to move multiple files with \`fs-ops\` nodes?

**URL:** <https://discourse.nodered.org/t/how-to-move-multiple-files-with-fs-ops-nodes/23394>\
**Category:** General\
**Created:** [21 March 2020 08:36 UTC](https://discourse.nodered.org/t/how-to-move-multiple-files-with-fs-ops-nodes/23394 "2020-03-21T08:36:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 March 2020 08:36 UTC](https://discourse.nodered.org/t/how-to-move-multiple-files-with-fs-ops-nodes/23394/1 "2020-03-21T08:36:14Z")

</div>

I have (yet) another problem when I am wanting to move multiple files from _a_ to _b_.

I have _these_ files in a directory (I just realised there is a _better_ way of doing it, but it will still require the same mechanics to work anyway).

There is one file: `last_alive.db` which is a _heart beat_ file and it is updated every _x_ seconds.  
When the machine reboots, it moves that file to a file called: `Rebooted at xxxxxxx`.

As you can see it is becoming cluttered (but that aside) every week it will move any **Rebooted at ......** files to a directory which is the year and week number.

I've got the directory making working, but not the moving.

This is the node (with settings):  
(Given the `global` variables are set)

```auto
[{"id":"823d9015.e08be","type":"fs-ops-move","z":"675e227d.d158b4","name":"","sourcePath":"source","sourcePathType":"msg","sourceFilename":"Reboot*","sourceFilenameType":"str","destPath":"destination","destPathType":"msg","destFilename":"*","destFilenameType":"str","link":false,"x":790,"y":2080,"wires":[["ff10ceb0.1de5"]]}]

```

But getting the file name part has me stumped.

---

<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:** [21 March 2020 11:35 UTC](https://discourse.nodered.org/t/how-to-move-multiple-files-with-fs-ops-nodes/23394/2 "2020-03-21T11:35:50Z")

</div>

Hi.

Few questions...

- What is `msg.source` set to
- what is `msg.destination` set to
- is the file _really_ called `Reboot*`?

my guess is you are trying to wild card this file name?

I'm not certain fs-ops move node supports wildcard file names - but the `directory` node does.

You'll likely have to use the `directory` node to get a list of files in `msg.source` then run through the array - then create a new `msg` with the file name set into a msg property then send that to the `move` node

---

<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:** [21 March 2020 11:51 UTC](https://discourse.nodered.org/t/how-to-move-multiple-files-with-fs-ops-nodes/23394/3 "2020-03-21T11:51:34Z")

</div>

Because I have nowt else to do 😉

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b3e1116a8020500cc981aa1ec8180886e77367c2.png)

```auto
[{"id":"c083b11f.d977e","type":"fs-ops-dir","z":"3aef9fe3.fda76","name":"get list of files matching Reboot*","path":"sourcePath","pathType":"msg","filter":"Reboot*","filterType":"str","dir":"payload","dirType":"msg","x":590,"y":260,"wires":[["bc4d99d9.c71808"]]},{"id":"2d1efb4c.458034","type":"inject","z":"3aef9fe3.fda76","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":260,"wires":[["4a18d5a3.4c13cc"]]},{"id":"f368ea49.769748","type":"fs-ops-move","z":"3aef9fe3.fda76","name":"","sourcePath":"sourcePath","sourcePathType":"msg","sourceFilename":"payload","sourceFilenameType":"msg","destPath":"destinationPath","destPathType":"msg","destFilename":"payload","destFilenameType":"msg","link":false,"x":660,"y":320,"wires":[[]]},{"id":"4a18d5a3.4c13cc","type":"change","z":"3aef9fe3.fda76","name":"","rules":[{"t":"set","p":"sourcePath","pt":"msg","to":"c:\\temp","tot":"str"},{"t":"set","p":"destinationPath","pt":"msg","to":"c:\\temp2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":260,"wires":[["c083b11f.d977e"]]},{"id":"bc4d99d9.c71808","type":"split","z":"3aef9fe3.fda76","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":510,"y":320,"wires":[["d7ddfa7e.1755a8","f368ea49.769748"]]},{"id":"d7ddfa7e.1755a8","type":"debug","z":"3aef9fe3.fda76","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":650,"y":380,"wires":[]}]

```

PS - I updated the title of your thread to better explain your requirement (to help others when looking for similar solution)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 March 2020 22:25 UTC](https://discourse.nodered.org/t/how-to-move-multiple-files-with-fs-ops-nodes/23394/4 "2020-03-21T22:25:00Z")

</div>

Ah! `split`!

(At time of posting it still isn't working, but I am looking at it because I probably have something set wrong)

Further reading shows me that I need to use `msg.payload` to carry the names of the files.  
Not `msg.files`. ☹

Reading the docs I saw that the file names were _saved_ to something which is compatible with other `fs-ops` nodes.

> List of file names is stored in an array in the specified property. This array is suitable for passing to other fs-op nodes for further operations.

But I didn't think to put the `split` node between them. (T'would be nice if that was explained better.)

Anyway.

> [@Steve-Mcl](#):
>
> my guess is you are trying to wild card this file name?

Yes. The file/s are called `Rebooted at YYYY-dd-mm HHmmss.txt`

I've changed some of the names while learning/reading stuff and because I was shown how to use the `template` node correctly.

Names:  
directory `/media/pi/06BB-C87D/logs/reboot/2020-12/`  
destination `/media/pi/06BB-C87D/logs/reboot/2020-12/`  
path `/media/pi/06BB-C87D/logs/`  
payload `/media/pi/06BB-C87D/logs/reboot/`

This is the flow as it stands now:

```auto
[{"id":"9b37182c.7af298","type":"delay","z":"675e227d.d158b4","name":"Delay","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":570,"y":2150,"wires":[["101f7e8a.bf1319"]]},{"id":"101f7e8a.bf1319","type":"split","z":"675e227d.d158b4","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":780,"y":2150,"wires":[["823d9015.e08be","5beb0e3d.de20b"]]},{"id":"4041d2b2.18dad4","type":"function","z":"675e227d.d158b4","name":"Build stuff","func":"msg.destination = msg.payload + msg.directory;\nreturn msg;","outputs":1,"noerr":0,"x":790,"y":2030,"wires":[["f38ba075.85be2","d5e9569e.50cea","c60b20e3.1bfec8","9b37182c.7af298"]]},{"id":"c60b20e3.1bfec8","type":"fs-ops-mkdir","z":"675e227d.d158b4","name":"","path":"payload","pathType":"msg","dirname":"directory","dirnameType":"msg","mode":"777","fullpath":"directory","fullpathType":"msg","x":600,"y":2110,"wires":[["dccc27aa.d4186"]]},{"id":"d5e9569e.50cea","type":"debug","z":"675e227d.d158b4","name":"IN","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":570,"y":2070,"wires":[]},{"id":"823d9015.e08be","type":"fs-ops-move","z":"675e227d.d158b4","name":"","sourcePath":"payload","sourcePathType":"msg","sourceFilename":"files","sourceFilenameType":"msg","destPath":"destination","destPathType":"msg","destFilename":"files","destFilenameType":"msg","link":false,"x":940,"y":2150,"wires":[["ff10ceb0.1de5"]]},{"id":"5beb0e3d.de20b","type":"debug","z":"675e227d.d158b4","name":"1d","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":930,"y":2190,"wires":[]},{"id":"570a0b23.860d0c","type":"fs-ops-dir","z":"675e227d.d158b4","name":"","path":"payload","pathType":"msg","filter":"Rebooted at*","filterType":"str","dir":"files","dirType":"msg","x":580,"y":2030,"wires":[["3c25455c.e66b0a","4041d2b2.18dad4"]]},{"id":"dccc27aa.d4186","type":"debug","z":"675e227d.d158b4","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":780,"y":2110,"wires":[]},{"id":"ff10ceb0.1de5","type":"debug","z":"675e227d.d158b4","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1090,"y":2150,"wires":[]},{"id":"791399b9.493ee","type":"template","z":"675e227d.d158b4","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{{path}}}reboot/","output":"str","x":350,"y":2030,"wires":[["74e6ce8a.becc68","570a0b23.860d0c"]]},{"id":"3c25455c.e66b0a","type":"debug","z":"675e227d.d158b4","name":"OUT","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":780,"y":1990,"wires":[]},{"id":"8ed6e064.5d98e","type":"change","z":"675e227d.d158b4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"directory","tot":"msg"},{"t":"set","p":"path","pt":"msg","to":"log_paths","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":1990,"wires":[["791399b9.493ee","8921a9ee.bfb6d8"]]},{"id":"74e6ce8a.becc68","type":"debug","z":"675e227d.d158b4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":570,"y":1950,"wires":[]},{"id":"c99fea29.aeaf1","type":"moment","z":"675e227d.d158b4","name":"","topic":"","input":"","inputType":"msg","inTz":"Australia/Sydney","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-ww/","locale":"en_AU","output":"","outputType":"msg","outTz":"Australia/Sydney","x":390,"y":1990,"wires":[["8ed6e064.5d98e"]]},{"id":"8921a9ee.bfb6d8","type":"debug","z":"675e227d.d158b4","name":"RAW","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":780,"y":1950,"wires":[]},{"id":"efce41db.b9d1c","type":"inject","z":"675e227d.d158b4","name":"Test","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":380,"y":2260,"wires":[["c99fea29.aeaf1"]]}]

```

---

<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:** [21 March 2020 22:31 UTC](https://discourse.nodered.org/t/how-to-move-multiple-files-with-fs-ops-nodes/23394/5 "2020-03-21T22:31:13Z")

</div>

Hi, you code doesnt work because `split` operates on msg.payload (not msg.files)

The code I posted works - try building around that instead.

[edit] - I think you already realize that. 🙂

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 March 2020 22:33 UTC](https://discourse.nodered.org/t/how-to-move-multiple-files-with-fs-ops-nodes/23394/6 "2020-03-21T22:33:19Z")

</div>

Yeah, I realised that after putting in the `split` node and it still not working.

(Typically)

I then looked at the `split` node and read how it only works on `msg.payload`.

Yeah, I am moving things around to free up `msg.payload` so it can carry the file names.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 March 2020 22:58 UTC](https://discourse.nodered.org/t/how-to-move-multiple-files-with-fs-ops-nodes/23394/7 "2020-03-21T22:58:31Z")

</div>

Thanks @Steve-Mcl

Yeah, now it is working.

I can't believe how _stupid_ I am and how many times I had to go over the nodes - even after re-making the names - to get rid of mistakes.

I guess it will just have to chalked up to learning.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [22 March 2020 00:13 UTC](https://discourse.nodered.org/t/how-to-move-multiple-files-with-fs-ops-nodes/23394/8 "2020-03-22T00:13:03Z")

</div>

To be even _smarter_ I now added another node after the `fs-ops-directory` node thus:

```auto
[{"id":"518603eb.e2199c","type":"switch","z":"b95543c8.1478f8","name":"","property":"payload[0]","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":680,"y":370,"wires":[["384f0968.70a6ce"]]}]

```

So if there are no files it doesn't go further.

---

<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:** [5 April 2020 00:13 UTC](https://discourse.nodered.org/t/how-to-move-multiple-files-with-fs-ops-nodes/23394/9 "2020-04-05T00:13:04Z")

</div>

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