Batch Script to Resize *.jpg in Folder and Subfolders

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: XnTriq, helmut, xnview

Erik_IG
Posts: 1
Joined: Fri Oct 23, 2015 9:58 am

Batch Script to Resize *.jpg in Folder and Subfolders

Post by Erik_IG »

Hi all,

I am looking for an automated process to periodically let NConvert resize all my .jpg files on a server based on folders and subfolders.
Currently I got a script working but that one only allows resizing the files in the specific folder, I need it to include all subfolders as well.

Code: Select all

nconvert -overwrite -ratio -rtype lanczos -rflag decr -resize 1920 1200 *.*
Any idea what I need to include into this script to get it working on subfolders as well ?

Many thanks,

Erik
cday
XnThusiast
Posts: 4186
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Batch Script to Resize *.jpg in Folder and Subfolders

Post by cday »

Erik_IG wrote:I am looking for an automated process to periodically let NConvert resize all my .jpg files on a server based on folders and subfolders.
Currently I got a script working but that one only allows resizing the files in the specific folder, I need it to include all subfolders as well.

Code: Select all

nconvert -overwrite -ratio -rtype lanczos -rflag decr -resize 1920 1200 *.*
Any idea what I need to include into this script to get it working on subfolders as well?
While the GUI XnView software (XnView Classic, XnViewMP and XnConvert) batch convert functions all have an option to keep the folder structure, there is no mention of a recursive option in the NConvert Help file, and the following posts seem to suggest that recursion isn't supported:

Recursive

recursive

I'm no command line expert, but when the folder structure is fixed, could the desired result possibly be achieved by using wildcards in the file paths??

If you do try that please proceed with great caution, and it would be interesting to know the result... :wink: :?:
User avatar
oops66
XnThusiast
Posts: 2005
Joined: Tue Jul 17, 2007 1:17 am
Location: France

Re: Batch Script to Resize *.jpg in Folder and Subfolders

Post by oops66 »

Erik_IG wrote:Any idea what I need to include into this script to get it working on subfolders as well ?
Hello,
Maybe you can try something like that, with a find cmd (here for linux) ( in a terminal, find "." from the root directory of the jpg)

Code: Select all

cd yourrootdirectoryofyourjpg
find . -iname "*.jpg" -exec nconvert -overwrite -ratio -rtype lanczos -rflag decr -resize 1920 1200 {} \;
XnViewMP Linux X64 - Debian - X64