Rename file based on contents

Post Reply
netaware
Member
Posts: 20
Joined: Tue Jul 30, 2024 7:11 pm

Rename file based on contents

Post 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.
User avatar
JimmyHartington
Advanced member
Posts: 461
Joined: Tue Mar 22, 2011 7:38 am

Re: Rename file based on contents

Post 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.
freddyp
Advanced member
Posts: 1130
Joined: Thu Feb 09, 2012 3:53 pm

Re: Rename file based on contents

Post 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
Post Reply