Page 1 of 1

Rename file based on contents

Posted: Wed Jul 02, 2025 7:07 pm
by netaware
Hello,
Is it possible for Switch to rename a text file or add a suffix/prefix based on its size or contents?

Or do I need to write a script?

Thanks.

Re: Rename file based on contents

Posted: Wed Jul 02, 2025 9:06 pm
by JimmyHartington
If it is the file size, you have the variable [Job.Size] which can be used in a rename element.

For contents you could use the Run Command app.
The it should be a command which outputs the contents of the file to the standard output, which then is private data that can be used to rename the file.
For example if the structure is consistent and the textfile needs to be renamed with the text in the second line of the text-file.
On macOS this can be done with this code:

Code: Select all

sed -n '2p' filename.txt
That could the be the command for Run Command.
In the Standard Output private data tag you will then have the second line and can use that to rename.

Re: Rename file based on contents

Posted: Thu Jul 03, 2025 8:05 am
by freddyp
Depending on the complexity of the contents of the text file you may find this app useful: https://www0.enfocus.com/en/appstore/product/txt-pickup