Rename image conversion to parent folder name

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Posts: 11
Joined: 2018-10-16T03:29:47-07:00
Authentication code: 1152

Rename image conversion to parent folder name

Post by keljnr » 2018-10-16T03:41:51-07:00

I have a simple script to convert all jpegs in a folder into one pdf:

Code: Select all

magick *jpg* myfile.pdf
Is it possible to rename the myfile.pdf to the folder name it sits in? So if the jpgs are in a folder called 'myFolder', the pdf will be myFolder.pdf

I have a lot of folders with images and don't want to manually retype the pdf filename.

Many thanks.

Posts: 11932
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Rename image conversion to parent folder name

Post by snibgo » 2018-10-16T08:00:47-07:00

You would need to decide on the rules when in a nested folder, eg /mydir/mydir2/abc.pdf. What do you want the new name to be?

You might do this by setting a shell variable before the magick command, or renaming afterwards.
snibgo's IM pages:

Post Reply