Processing Subfolders

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
TSchlaier01
Posts: 10
Joined: 2010-03-22T02:57:35-07:00
Authentication code: 8675308

Processing Subfolders

Post by TSchlaier01 »

I know there are a few topics about a similar problem but I wasn't able to find a solution in the replies.

I want to process a folder including all subfolders. My (Batch)Script does that using the /R command but it saves all the results into the root directory.

Code: Select all

for /R %%f in (*.jpg) do ( convert "%%f" -resize 2480x3508 "%%~nf.jpg" )
I want to overwrite the original files in the subdirectories keeping the filenames.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Processing Subfolders

Post by anthony »

See IM Examples, Windows Usage
http://www.imagemagick.org/Usage/windows/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
TSchlaier01
Posts: 10
Joined: 2010-03-22T02:57:35-07:00
Authentication code: 8675308

Re: Processing Subfolders

Post by TSchlaier01 »

I know that but I can't find a solution there.
The first example saves all output files into the root directory.

All the other examples there are very complex, using multiple batch files.

Isn't it possible to solve that problem with a single command? All I want to do is overwriting the existing files where they are!?
almuhammedi
Posts: 1
Joined: 2012-08-21T08:38:36-07:00
Authentication code: 67789

Re: Processing Subfolders

Post by almuhammedi »

Try this

Code: Select all

    for /R %%f in (*.jpg) do ( convert "%%f" -resize 2480x3508 "%%~npf.jpg" )
Regards,
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

Re: Processing Subfolders

Post by pipitas »

I'm always hesitant to overwrite original files... but you asked for it :-)

The shortest ImageMagick command to manipulate images 'inline' is mogrify:

Code: Select all

for  /R %%f  in (*.jpg)  do  mogrify  -resize 2480x3508  "%%f"
You can of course use convert too, but then you'll have to specifically set the output file path+name too...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Processing Subfolders

Post by fmw42 »

with mogrify you can set the -path for the output directory so that you do not write over your input images
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Processing Subfolders

Post by whugemann »

Well, the simplest code to perform this job is just
FOR /R %%f IN (*.jpg) DO convert "%%f" -resize 2480x3508 "%%f"

The code is so easy is that I would just type it into a CMD box, in which case it would be
FOR /R %f IN (*.jpg) DO convert "%f" -resize 2480x3508 "%f"

I intentionally don't give examples like that on the Windows Usage page, because I would rather never do a thing like that, i.e. possibly overwriting thousands of files.
Wolfgang Hugemann
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

Re: Processing Subfolders

Post by pipitas »

whugemann wrote:Well, the simplest code to perform this job is just
FOR /R %%f IN (*.jpg) DO convert "%%f" -resize 2480x3508 "%%f"
So you think that's simpler than using 'mogrify' with only 1 occurrence of '%%f' ??

I share your hesitation to overwrite files, though. ;-)
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Processing Subfolders

Post by whugemann »

pipitas wrote: So you think that's simpler than using 'mogrify' with only 1 occurrence of '%%f' ??
I should have written "the most straightforward way for an IM beginner" instead of "simpler". To me, Mogrify is one of the more exotic command line tools. The IM beginner is probably more used to Convert.
Wolfgang Hugemann
Post Reply