# rename (FTP command)

### Overview

The `rename` command changes the name of specified files. You can [rename single/multiple files and leave them in the same directory](#renaming-but-not-moving-a-file), or you can [rename files into a different directory](#renaming-and-moving-a-file).

## Need to know

* No content is loaded into the flow. A boolean value is returned to indicate a successful/failed file operation.
* Regular expressions are supported in filenames.

## Connection settings

When [configuring an SFTP connector](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/connector-shape/configuring-sftp-connections), three fields should be updated:

| FTP command                                                                             | Root                                              | Path                                            |
| --------------------------------------------------------------------------------------- | ------------------------------------------------- | ----------------------------------------------- |
| FTP command followed by the required directory and name for the file when it's renamed. | The common root to source and target directories. | The source directory and file(s) to be renamed. |

## Examples

* [Rename but don't move a file](#renaming-but-not-moving-a-file)
* [Rename & move a file](#renaming-and-moving-a-file)

### Renaming but not moving a file&#x20;

* [Scenario](#scenario)
* [The steps](#the-steps)

#### Scenario

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="image">Cover image</th></tr></thead><tbody><tr><td><p>Our process flow is configured as below:</p><div><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F7RXIffojQlnoHGyfM6OA%2Frename%20single%20file%20same%20folder%20-%20flow.png?alt=media&#x26;token=7df4c219-a367-4145-be1a-131525c6ce3c" alt=""><figcaption></figcaption></figure></div></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fn8hT31RXr15yDkexZJE3%2Fpatchworks%20tile.png?alt=media&#x26;token=bfe93287-e388-4fc4-98d4-9f7f4d4ad145">patchworks tile.png</a></td></tr><tr><td><p>In this flow, we need to rename a file named <code>hello.txt</code> in <code>/myfiles/folderC</code> to <code>goodbye.txt</code>:<br><br><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FMt1F7rCZVP1ec7uLoS1g%2Frename%20single%20file%20same%20folder%20-%20files%20before.png?alt=media&#x26;token=a3c1d286-1df9-4ba8-9b24-32a0c4b33593" alt=""></p><p></p><p>We want the renamed file to end up in the same directory.</p></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FLk4y0aH1PczueqSMTLXB%2Fsftp%20tile.png?alt=media&#x26;token=09c2c0cd-72cc-4c34-b43e-a494256f60d5">sftp tile.png</a></td></tr></tbody></table>

#### The steps

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="image">Cover image</th></tr></thead><tbody><tr><td><p><strong>Connector settings</strong></p><p>Our SFTP shape is configured as follows: </p><div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FkKyHi2BOPDp9y4L2yn3D%2Frename%20single%20file%20same%20folder%20-%20sftp%20settings.png?alt=media&#x26;token=da9e9836-7d80-4404-8b72-8e9678608185" alt=""><figcaption></figcaption></figure></div><ul><li>Use the <code>SFTP GET user pass</code> endpoint.</li><li>Start looking for the file to rename from the <code>root</code>, which is defined as: <code>/myfiles/</code></li><li>Check the <code>path</code> for the file to rename, which is defined as: <code>folderC/hello.txt</code></li><li>Rename the file to the directory/name provided immediately after the <code>ftp command</code>. This is defined as: <code>rename:folderC/goodbye.txt</code>   </li></ul></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fj6MRefKqIGHibXcacRDK%2F1.png?alt=media&#x26;token=b29dc3c5-6a7d-406c-b1ea-4a42fa659f86">1.png</a></td></tr><tr><td><p><strong>Payload &#x26; SFTP server</strong> </p><p>When the process flow is run, the payload for our SFTP shape shows just a <code>1</code>: </p><div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FvRq6K4zexKsqttcKhwIE%2Frename%20single%20file%20same%20folder%20-%20sftp%20payload.png?alt=media&#x26;token=49313b4a-fcc4-49c9-a331-8260ef013cf6" alt=""><figcaption></figcaption></figure></div><p>A <code>1</code> indicates a successful response from your remote server. A <code>0</code> indicates an unsuccessful response. </p><p></p><p>On our remote server, <code>hello.txt</code> is now named <code>goodbye.txt</code> (still in <code>/folderC</code>):<br><br><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FU2bjjFuGsSCqLoEtWX9e%2Frename%20single%20file%20same%20folder%20-%20files%20after.png?alt=media&#x26;token=8c84b927-1bec-4645-88cc-16dccd797a05" alt=""></p><p></p></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FHGWG2ZNqxBfnjG0EpNCG%2F2.png?alt=media&#x26;token=0364622b-8254-4551-9a68-9e2f142f330f">2.png</a></td></tr></tbody></table>

### Renaming & moving a file

* [Scenario](#scenario)
* [The steps](#the-steps)

#### Scenario

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="image">Cover image</th></tr></thead><tbody><tr><td><p>Our process flow is configured as follows:</p><div><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FPLuYUEJv4WR6BjH0O1Ke%2Frename%20and%20move%20sftp%20-%20flow.png?alt=media&#x26;token=c3e8f201-88b0-4a1e-9dc9-fc1ba0802ccb" alt=""><figcaption></figcaption></figure></div></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fn8hT31RXr15yDkexZJE3%2Fpatchworks%20tile.png?alt=media&#x26;token=bfe93287-e388-4fc4-98d4-9f7f4d4ad145">patchworks tile.png</a></td></tr><tr><td>In this flow, we need to <code>rename</code> <code>/myfiles/folderE/hello.txt</code>:<br><br><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FyWBCVXSDTPjiVPakvlzR%2Frename%20and%20move%20-%20files%20before%20c.png?alt=media&#x26;token=7876d357-7be3-466b-a8b5-4c9daae325a7" alt=""><br><br>The file will be renamed as <code>/myfiles/folderF/goodbye.txt</code> - so we are both moving and renaming the file:<br><br><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FIww5V9BoHdqjJYo7faq7%2Frename%20and%20move%20-%20files%20before%20b.png?alt=media&#x26;token=12474695-0331-46da-b30e-81f63b7d5a5f" alt=""></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FLk4y0aH1PczueqSMTLXB%2Fsftp%20tile.png?alt=media&#x26;token=09c2c0cd-72cc-4c34-b43e-a494256f60d5">sftp tile.png</a></td></tr></tbody></table>

#### The steps

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="image">Cover image</th></tr></thead><tbody><tr><td><p><strong>Connector settings for SFTP shape</strong></p><p>Our first <code>SFTP connector</code> step is configured as follows: </p><div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FHCjgzvXd0FICf6Icua1n%2Frename%20and%20move%20sftp%20-%20connector%20settings%20a.png?alt=media&#x26;token=f753eb41-36a4-4055-a51c-25523436e55c" alt=""><figcaption></figcaption></figure></div><ul><li>Use the <code>SFTP GET user pass</code> endpoint.</li><li>Start looking for the file to rename from the <code>root</code>, which is defined as: <code>/myfiles/</code></li><li>Check the <code>path</code> for the file to rename, which is defined as: <code>folderE/hello.txt</code></li><li>Rename the file to the directory/name provided immediately after the <code>ftp command</code>. This is defined as: <code>rename:folderF/goodbye.txt</code></li></ul></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fj6MRefKqIGHibXcacRDK%2F1.png?alt=media&#x26;token=b29dc3c5-6a7d-406c-b1ea-4a42fa659f86">1.png</a></td></tr><tr><td><p><strong>Payload</strong> <strong>for SFTP shape</strong><br>When the process flow is run, the payload for our SFTP shape shows just a <code>1</code>: </p><div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FvRq6K4zexKsqttcKhwIE%2Frename%20single%20file%20same%20folder%20-%20sftp%20payload.png?alt=media&#x26;token=49313b4a-fcc4-49c9-a331-8260ef013cf6" alt=""><figcaption></figcaption></figure></div><p>A <code>1</code> indicates a successful response from your remote server. A <code>0</code> indicates an unsuccessful response. </p><p><br><br></p></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FeprQ8ZSUTgwLb4o6Jxvy%2F2.png?alt=media&#x26;token=c4fc14d2-0f0f-4487-8757-e4af51a32614">2.png</a></td></tr><tr><td><p><strong>Remote server outcome</strong>  </p><p>On our remote server, <code>hello.txt</code> is gone from <code>/myfiles/folderE</code>: <br><br><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fh0WKDWnlKvTyTCewYJxh%2Frename%20and%20move%20-%20files%20after%20b.png?alt=media&#x26;token=0ed15d26-8d5f-4ac5-85d9-3816d12d544d" alt=""></p><p><br>But now we have a file named, <code>goodbye.txt</code> in <code>/myfiles/folderF</code>: </p><p></p><p><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FlPyRLQUu8esfzopCkh8p%2Frename%20and%20move%20-%20files%20after.png?alt=media&#x26;token=9edd5f64-d625-42e6-af15-e2b6bb594ef7" alt=""><br></p></td><td><a href="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FFGZGpJpRS5MqirFAp1J0%2F3.png?alt=media&#x26;token=1bf1b9f1-37ca-4926-9abc-121b4566bad7">3.png</a></td></tr></tbody></table>
