Script to convert BMP to JPG, Need help completing.

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
wattup
Posts: 2
Joined: 2019-02-25T07:58:10-07:00
Authentication code: 1152

Script to convert BMP to JPG, Need help completing.

Post by wattup »

Windows 10 system, using cmd

I have a NAS full of images, buried deep in a series of subfolders. I am trying to write a script to reduce all images older than 90days from BMP to jpg.

What I have so far,

forfiles /P [dir1\dir2\....] /S /M *.bmp /D -90 /C "cmd /c magick morgify @fname -format jpg *.bmp"

When i run this command, it does process the BMP to JPG as needed, but it then tries to run again and again creating ~jpg files and errors in cmd line i assume bc the jpg file names exist.

What I also need is a way to remove the original BMP file, my NAS is 0.06% empty and can't afford to create double pictures
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Script to convert BMP to JPG, Need help completing.

Post by snibgo »

"magick mogrify" loops through all the files in its input filename, in your case "*.bmp". But you have this inside a "forfiles" loop which loops through "*.bmp". So every file is processed twice.

I suggest you use "forfiles" with "magick", so the magick command processes only one file at a time. You can also have a "delete" command within the loop.
snibgo's IM pages: im.snibgo.com
wattup
Posts: 2
Joined: 2019-02-25T07:58:10-07:00
Authentication code: 1152

Re: Script to convert BMP to JPG, Need help completing.

Post by wattup »

Thanks for that @snibgo

I was able to create a pretty decent script once i remembered i can link CMDs with &

my final working script is:

forfiles /S /M *.bmp /D -120 /C "cmd /c echo @file & convert @file @fname.jpg & DEL @file"
Post Reply