This is probably easy but I'm having trouble finding the proper commands and scripting isn't my expertise. I've gone through the examples and searched the documentation multiple times over the past couple days. Any assistance is greatly appreciated.
I'm trying to convert and merge image files based on a partial match of the file name. I've been able to script entire directories and target specific filetypes for conversion/mogrify and merging, but now I'm looking to target those based on matching characters of a filename. My example below might better explain it.
Source file list - format is "type_name_pagenumber.filetype":
fruit_orange_1.tif (single page)
fruit_orange_2.tif (single page)
fruit_orange_3.tif (single page)
fruit_banana_1.tif (single page)
fruit_banana_2.tif (single page)
fruit_apples_1.pdf
fruit_tomato_1.pdf
End result I'm aiming for:
fruit_orange.tif (combined multipage - 3 pages)
fruit_banana.tif (combined multipage - 2 pages)
fruit_apples_1.pdf (untouched)
fruit_tomato_1.pdf (untouched)
In the above example, the TIF files have a type prefix (fruit) that will remain the same forever but the following name (orange) and page number (#) will change daily. I'd like to merge all files that have a matching "type_name_" in the filename of the .TIF filetype. The filenames are a fixed length, down to the type, name, page number and filetype.
After the files that belong together are together, I'd convert them to PDF, which I'm already familiar with.
Is the above possible?
How do I merge files with partial filename matches
Re: How do I merge files with partial filename matches
Forgot to mention, we are running IM-7.0.4-Q16.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How do I merge files with partial filename matches
I suspect this is most easily done with your script language. Which you haven't mentioned.
snibgo's IM pages: im.snibgo.com
Re: How do I merge files with partial filename matches
Let me ask the following, as it might help me down the right path to getting this scripted with powershell.
If I want to put multiple single page tif files and put them into a multipage tif, what is the best IM command and syntax for targeting multiple files by name?
If I want to put multiple single page tif files and put them into a multipage pdf, what is the best IM command and syntax for targeting multiple files by name?
If I want to put multiple single page tif files and put them into a multipage tif, what is the best IM command and syntax for targeting multiple files by name?
If I want to put multiple single page tif files and put them into a multipage pdf, what is the best IM command and syntax for targeting multiple files by name?
Re: How do I merge files with partial filename matches
I have never tried it but you may be looking for: https://www.imagemagick.org/script/comm ... php#adjoin
So I guess the code would look something like:
You might be able to use a text file for the input or create a command using a concat type function and a loop over the files in your code.
So I guess the code would look something like:
Code: Select all
convert input1.tiff input2.tiff input3.tiff -adjoin output.tiff
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How do I merge files with partial filename matches
Or you could do it with wildcards.
For IM v6:
For IM v7:
If each input set has a _1.tif, that may be a convenient way of finding what sets exist.
For IM v6:
Code: Select all
convert fruit_orange_*.tif fruit_orange.tif
Code: Select all
magick fruit_orange_*.tif fruit_orange.tif
snibgo's IM pages: im.snibgo.com
Re: How do I merge files with partial filename matches
Thanks for the suggestion on wildcards, but both the "orange" and number parts of the file name will always be changing and dynamic in nature. It is a fixed length but I will never know what those file names will be.
And while my example uses it, the number portion is actually a six character hex value, that is also dynamic but can't be used for sorting out the files, like the first 13 characters can. I just put it as a single digit to simplify the example.
And while my example uses it, the number portion is actually a six character hex value, that is also dynamic but can't be used for sorting out the files, like the first 13 characters can. I just put it as a single digit to simplify the example.
Re: How do I merge files with partial filename matches
Thanks! That is the format I'm using when manually running the command against test files, so that helps confirm I'm doing something right.Bonzo wrote: ↑2017-04-25T12:12:32-07:00 I have never tried it but you may be looking for: https://www.imagemagick.org/script/comm ... php#adjoin
So I guess the code would look something like:You might be able to use a text file for the input or create a command using a concat type function and a loop over the files in your code.Code: Select all
convert input1.tiff input2.tiff input3.tiff -adjoin output.tiff
Now I just need to figure out the powershell portion of sorting out files and piping them into the convert command with the right format.