Page 1 of 1

Script to convert BMP to JPG, Need help completing.

Posted: 2019-02-25T08:11:37-07:00
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

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

Posted: 2019-02-25T16:14:01-07:00
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.

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

Posted: 2019-02-27T07:52:35-07:00
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"