CMD NConvert All images in the catalog

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

Moderators: XnTriq, helmut, xnview

Post Reply
NikolayHAOS1
Posts: 4
Joined: Mon Mar 01, 2021 9:06 am

CMD NConvert All images in the catalog

Post by NikolayHAOS1 »

Hello.
I use Google translate.
I ask for help.
The question is, for example, "resize the image on the long side" to 1024 pixels and rename it as ###.JPG with the removal of the source.
In the directory D:\222\ and all its subfolders.
What the command line code should look like using NConvert
cday
XnThusiast
Posts: 3973
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: CMD NConvert All images in the catalog

Post by cday »

NikolayHAOS1 wrote: Mon Mar 01, 2021 9:16 am Hello, I use Google translate, I ask for help.
How to, for example, "resize the image on the long side" to 1024 pixels and rename it as ###.JPG with the removal of the source.

What the command line code should look like using NConvert?
Do you have a copy of the NConvert help file, copy for the current NConvert 7.70 attached.

In the directory D:\222\ and all its subfolders.
Using CMD I believe it is only possible to convert files in folders down one level...

If you need to convert files in folder more than one level down, that may be possible using Powershell?? or Linux??

If you need to convert files to a deeper level in a folder tree, have you considered using the GUI software XnConvert which I think can do that?

NConvert 7.70 Help.txt.zip
(10.59 KiB) Downloaded 52 times
NikolayHAOS1
Posts: 4
Joined: Mon Mar 01, 2021 9:06 am

Re: CMD NConvert All images in the catalog

Post by NikolayHAOS1 »

The code below works with subfolders.
BUT does not assign a name to the file.
Tell me how to complete the code.

Code: Select all

@chcp 1251
FOR /f "delims=*" %%A IN ('dir *.jpg /b /s')  do "D:\111\NConvert\nconvert" -ratio -rtype lanczos -resize longest 1024  -o $ -q 80 -opthuff "%%A"
cday
XnThusiast
Posts: 3973
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: CMD NConvert All images in the catalog

Post by cday »

Code: Select all

-o filename       : Output filename
              Use # to specify position of numeric enumerator
              Use % to specify source filename
              Use $ to specify full source pathname
              Use $$ to specify source folder name
              Use $EXIF:DateModified[date format] to specify EXIF date modified
              Use $EXIF:DateTaken[date format] to specify EXIF date taken
									Date format: Please check documentation of strftime

Code: Select all

-out format       : Output format name
So try -out jpeg -o %.jpg

Or more generally -out jpeg -o name###.jpg for example.

The -out jpeg term is possibly not needed for JPEG source files.

In a batch file .bat it is necessary to double % to %% to escape the character.

[Edited]
NikolayHAOS1
Posts: 4
Joined: Mon Mar 01, 2021 9:06 am

Re: CMD NConvert All images in the catalog

Post by NikolayHAOS1 »

Code: Select all

@chcp 1251
@for /R D:\333\ %%A in (*.png *.jpg *.jpeg *.gif *.bmp) do "D:\111\NConvert\nconvert" -ratio -o $\### -out jpeg -rtype lanczos -resize longest 1024 -q 80 -opthuff "%%A"
Processes newly created files.
How to exclude this.
cday
XnThusiast
Posts: 3973
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: CMD NConvert All images in the catalog

Post by cday »

NikolayHAOS1 wrote: Mon Mar 01, 2021 9:16 am The question is, for example, "resize the image on the long side" to 1024 pixels and rename it as ###.JPG with the removal of the source.
NikolayHAOS1 wrote: Tue Mar 02, 2021 5:11 am

Code: Select all

@chcp 1251
@for /R D:\333\ %%A in (*.png *.jpg *.jpeg *.gif *.bmp) do "D:\111\NConvert\nconvert" -ratio -o $\### -out jpeg -rtype lanczos -resize longest 1024 -q 80 -opthuff "%%A"
Processes newly created files.
How to exclude this.

The source files can be removed using this option:

Code: Select all

-D                : Delete original picture
Is that what you mean?
NikolayHAOS1
Posts: 4
Joined: Mon Mar 01, 2021 9:06 am

Re: CMD NConvert All images in the catalog

Post by NikolayHAOS1 »

They helped in the Russian forum. (https://www.cyberforum.ru/soft-graphics)
Here is a completely correct working code.

Code: Select all

@for /f "delims= eol=" %%d in ('dir/ad/b/s D:\SITE') do @pushd "%%d"&@D:\SOFT\NConvert\nconvert.exe -quiet -ratio -o $\### -out jpeg -rtype lanczos -resize longest 1024 -q 80 -opthuff -D *.jfif *.jpg *.jpeg *.png *.gif *.bmp
Last edited by NikolayHAOS1 on Thu Mar 04, 2021 6:11 am, edited 1 time in total.
cday
XnThusiast
Posts: 3973
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: CMD NConvert All images in the catalog

Post by cday »

Thank you for posting your final code, it may help someone else one day... :D
anfvan6
Posts: 10
Joined: Sun Mar 22, 2020 2:11 pm

Re: CMD NConvert All images in the catalog

Post by anfvan6 »

Я схожую необходимость решил следующим решением:

@Echo Off
SetLocal EnableDelayedExpansion
Set DataRoot="%1"
Set OutFile=out.txt
chcp 1251 > nul
For /F "delims=" %%A In ('Dir "%DataRoot%\" /B /A-D 2^>nul') Do (Echo %%~fA>>"%OutFile%")
For /F "delims=" %%A In ('Dir "%DataRoot%\" /S /B /AD') Do (
Set RelativePath=%%A
Set RelativePath=!RelativePath:%DataRoot%=!
For /F "delims=" %%B In ('Dir "%%~A" /B /A-D 2^>nul') Do (Echo !RelativePath!\%%~B>>"%OutFile%")
)
"C:\XnView\nconvert.exe" -out jpeg -ratio -rflag decr -resize longest 1024 -rtype lanczos -rmeta -overwrite -q 75 -opthuff -dct 3 -smoothingf 0 -subsampling 0 -l out.txt
del out.txt

два цикла в батнике формируют список файлов out.txt, которые следует преобразовать.
Этот батник я запускаю с панели Total Commander c параметром "%P" - это имя папки в которой нужно преобразовать все файлы включая в подпапках. Т.е. без тотала можно запустить бат с ключом названием папки типа "C:\XnView\"
cday
XnThusiast
Posts: 3973
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: CMD NConvert All images in the catalog

Post by cday »

anfvan6 wrote: Mon Mar 08, 2021 2:23 pm Я схожую необходимость решил следующим решением:

I solved a similar need with the following solution:
Thank you, that may help someone in the future... :D

I rarely use more than very basic CMD myself as my needs are limited, CMD is now rather old, very cryptic for more than basic use, and not well documented for easy reference for more complex use!
Post Reply