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.
Rename file based on contents
- JimmyHartington
- Advanced member
- Posts: 464
- Joined: Tue Mar 22, 2011 7:38 am
Re: Rename file based on contents
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:
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.
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
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
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
Re: Rename file based on contents
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 This is what i am getting with my assemble job
Thanks for your suggestions!
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 This is what i am getting with my assemble job
Thanks for your suggestions!
- JimmyHartington
- Advanced member
- Posts: 464
- Joined: Tue Mar 22, 2011 7:38 am
Re: Rename file based on contents
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?
Is the files assembled correctly, but the name of the job-folder is wrong?