Rename file based on contents

Post Reply
netaware
Member
Posts: 21
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: 464
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
netaware
Member
Posts: 21
Joined: Tue Jul 30, 2024 7:11 pm

Re: Rename file based on contents

Post by netaware »

Thanks but I think I maybe explained my problem wrong. I am looking to assemble a job from 2 different incoming folders, Folder 1 and Folder 2.
I assemble the job folder with 2 files, one from each incoming folder, based on a segment of the name, 1-23 positions.
This works fine except for most files. However, I have 2 files in each incoming folder that are almost exactly the same name:
Folder 1 - 3-M-JTSPAW-22025-2025100013-CDBD14.txt and 3-M-JTSPAW-22025-2025100013-CDBD15.txt
Folder 2 - 3-M-JTSPAW-22025-2025100028-CDC5BB.txt and 3-M-JTSPAW-22025-2025100028-CDC5BC.txt
NOTE: the first 11 characters are always the same, 3-M-JTSPAW-

The assemble app is assembling both files from Folder 1 together and both files from Folder 2 together.
How can I get it where it puts one file from Folder 1 and one file from Folder 2 together?
I understand the original filenames are close but I cannot do anything about it. I have rename job app remembering the original name.

Assemble job settings
Flow6.png
Flow6.png (21.49 KiB) Viewed 12 times
This is what i am getting with my assemble job
Flow5.png
Flow5.png (16.7 KiB) Viewed 12 times
Thanks for your suggestions!
User avatar
JimmyHartington
Advanced member
Posts: 464
Joined: Tue Mar 22, 2011 7:38 am

Re: Rename file based on contents

Post by JimmyHartington »

I am a bit unsure about what you want to achieve.

Is the files assembled correctly, but the name of the job-folder is wrong?
Post Reply