# Get filename of created files from exec

**URL:** <https://discourse.nodered.org/t/get-filename-of-created-files-from-exec/60599>\
**Category:** General\
**Created:** [31 March 2022 16:27 UTC](https://discourse.nodered.org/t/get-filename-of-created-files-from-exec/60599 "2022-03-31T16:27:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [31 March 2022 16:27 UTC](https://discourse.nodered.org/t/get-filename-of-created-files-from-exec/60599/1 "2022-03-31T16:27:09Z")

</div>

Hi!

I have a java program which is triggered by the exec node.  
The output of it are several files with different names. (automatically generated with timestamp in the name)

How would I get these names, then transfer them to a server via SFTP and afterwards delete them on the local server?  
Alternatively, it would be ok to say "move all files starting with "XYZ\_"" cause all of them start the same.

Thanks!

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [31 March 2022 16:34 UTC](https://discourse.nodered.org/t/get-filename-of-created-files-from-exec/60599/2 "2022-03-31T16:34:54Z")

</div>

Can you show us what the exec node produces by adding a debug node?

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [31 March 2022 16:40 UTC](https://discourse.nodered.org/t/get-filename-of-created-files-from-exec/60599/3 "2022-03-31T16:40:58Z")

</div>

The program just puts out some warnings from the java file as well as: {"code":0}  
But no filenames or so.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [31 March 2022 16:42 UTC](https://discourse.nodered.org/t/get-filename-of-created-files-from-exec/60599/4 "2022-03-31T16:42:48Z")

</div>

Can you post your flow?

---

<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:** [31 March 2022 17:11 UTC](https://discourse.nodered.org/t/get-filename-of-created-files-from-exec/60599/5 "2022-03-31T17:11:20Z")

</div>

> [@smitterer](#):
>
> move all files starting with "XYZ\_""

Yes, do that.

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [1 April 2022 06:38 UTC](https://discourse.nodered.org/t/get-filename-of-created-files-from-exec/60599/6 "2022-04-01T06:38:13Z")

</div>

Any idea how I would do this? Is there a node to get all files in a folder and then filter them?

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [1 April 2022 08:01 UTC](https://discourse.nodered.org/t/get-filename-of-created-files-from-exec/60599/7 "2022-04-01T08:01:26Z")

</div>

You could use the exec node to move the files using command line arguments.

On Linux:

```auto
cp --help

```

---

<div class="post-metadata">

**Author:** ![smitterer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smitterer/32/59179_2.png) [@smitterer](https://discourse.nodered.org/u/smitterer)\
**Post date:** [1 April 2022 09:31 UTC](https://discourse.nodered.org/t/get-filename-of-created-files-from-exec/60599/8 "2022-04-01T09:31:25Z")

</div>

Ok did it the following way now:

```auto
[
    {
        "id": "b2ff03a7268c4151",
        "type": "tab",
        "label": "SECRET",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "783c455e1d595834",
        "type": "exec",
        "z": "b2ff03a7268c4151",
        "command": "doesntmatter",
        "addpay": "",
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 550,
        "y": 160,
        "wires": [
            [
                "cea0cc643dbd4ffe"
            ],
            [],
            []
        ]
    },
    {
        "id": "297602128150a085",
        "type": "inject",
        "z": "b2ff03a7268c4151",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 140,
        "y": 160,
        "wires": [
            [
                "783c455e1d595834"
            ]
        ]
    },
    {
        "id": "cda84830c6810720",
        "type": "sftp in",
        "z": "b2ff03a7268c4151",
        "name": "anypath",
        "sftp": "",
        "operation": "put",
        "filename": "",
        "localFilename": "",
        "workdir": "/anypath",
        "x": 680,
        "y": 300,
        "wires": [
            [
                "e2b4c85b292843c4"
            ]
        ]
    },
    {
        "id": "cea0cc643dbd4ffe",
        "type": "fs-file-lister",
        "z": "b2ff03a7268c4151",
        "name": "",
        "start": "/anypath",
        "pattern": "ABC_*",
        "folders": "*",
        "hidden": true,
        "lstype": "files",
        "path": false,
        "single": false,
        "depth": 0,
        "stat": false,
        "showWarnings": true,
        "x": 240,
        "y": 240,
        "wires": [
            [
                "165da27c15677898"
            ]
        ]
    },
    {
        "id": "165da27c15677898",
        "type": "change",
        "z": "b2ff03a7268c4151",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "temp",
                "pt": "msg",
                "to": "payload",
                "tot": "msg",
                "dc": true
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{}",
                "tot": "json"
            },
            {
                "t": "set",
                "p": "payload.data",
                "pt": "msg",
                "to": "\"/somepath\" & msg.temp",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "payload.filename",
                "pt": "msg",
                "to": "temp",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 460,
        "y": 300,
        "wires": [
            [
                "cda84830c6810720"
            ]
        ]
    },
    {
        "id": "e2b4c85b292843c4",
        "type": "fs-ops-delete",
        "z": "b2ff03a7268c4151",
        "name": "",
        "path": "/anypath/",
        "pathType": "str",
        "filename": "temp",
        "filenameType": "msg",
        "x": 870,
        "y": 300,
        "wires": [
            []
        ]
    }
]

```

Thanks for your support

---

<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:** [15 April 2022 09:32 UTC](https://discourse.nodered.org/t/get-filename-of-created-files-from-exec/60599/9 "2022-04-15T09:32:17Z")

</div>

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