CMD NConvert All images in the catalog
Moderators: XnTriq, helmut, xnview
-
- Posts: 4
- Joined: Mon Mar 01, 2021 9:06 am
CMD NConvert All images in the catalog
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
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
-
- XnThusiast
- Posts: 4171
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: CMD NConvert All images in the catalog
Do you have a copy of the NConvert help file, copy for the current NConvert 7.70 attached.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?
Using CMD I believe it is only possible to convert files in folders down one level...In the directory D:\222\ and all its subfolders.
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?
You do not have the required permissions to view the files attached to this post.
-
- Posts: 4
- Joined: Mon Mar 01, 2021 9:06 am
Re: CMD NConvert All images in the catalog
The code below works with subfolders.
BUT does not assign a name to the file.
Tell me how to complete the code.
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"
-
- XnThusiast
- Posts: 4171
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: CMD NConvert All images in the catalog
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
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]
-
- Posts: 4
- Joined: Mon Mar 01, 2021 9:06 am
Re: CMD NConvert All images in the catalog
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"
How to exclude this.
-
- XnThusiast
- Posts: 4171
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: CMD NConvert All images in the catalog
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 amProcesses newly created files.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"
How to exclude this.
The source files can be removed using this option:
Code: Select all
-D : Delete original picture
-
- Posts: 4
- Joined: Mon Mar 01, 2021 9:06 am
Re: CMD NConvert All images in the catalog
They helped in the Russian forum. (https://www.cyberforum.ru/soft-graphics)
Here is a completely correct working code.
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.
-
- XnThusiast
- Posts: 4171
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: CMD NConvert All images in the catalog
Thank you for posting your final code, it may help someone else one day...
-
- Posts: 10
- Joined: Sun Mar 22, 2020 2:11 pm
Re: CMD NConvert All images in the catalog
Я схожую необходимость решил следующим решением:
@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\"
@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\"
-
- XnThusiast
- Posts: 4171
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: CMD NConvert All images in the catalog
Thank you, that may help someone in the future...
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!