Convert PICs from filelist, and keep directory-tree?

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

Moderators: XnTriq, xnview

Post Reply
Posts: 40
Joined: Wed Mar 22, 2006 1:08 pm

Convert PICs from filelist, and keep directory-tree?

Post by tom*de »

NCONVERT v4.70 (Nov 17 2006/15:26:07)

How can I convert pictures from directory and all its subdirectories and keep the directory-tree of the stores and converted files?
I tried to get this way over creating a filelist but I got the problem to keep the folders of the pictures from filelist in the destination directory...

The following command converts all files from a filelist into C:\TEST

Filelist has content like this:
and was created by using: "dir C:\PIC\ /A-D /S /B > C:\filelist.txt"
(by the way nconvert has problems, if the filenames has german umlauts äöü..) Can't open file... it should be optional to use the OEM DOS-Char set.)

Code: Select all

nconvert.exe -ratio -out jpeg -o "c:\test\%.jpg" -keepfiledate -q 80 -resize 800 800 -l C:\filelist.txt
An error message appears after conversion:
Conversion of c:\PIC\A.JPG into c:\test\A.jpg OK
Conversion of c:\PIC\SubDir1\B.JPG into c:\test\B.jpg OK
Conversion of c:\PIC\SubDir1\C.JPG into c:\test\C.jpg OK
=> C:\filelist.txt
=> C:\filelist.txt
Error: Don't know how to read this picture (C:\filelist.txt)

Okay the 3 converted PICs are successfully stored in C:\TEST, but I would like to keep the Directory-Structure, too... therefore my question: How can I keep the folders of the pictures from filelist in the destination directory C:\TEST:

I tried this command by modifying the option -o:

Code: Select all

nconvert.exe -ratio -out jpeg -o "$%.jpg" -keepfiledate -q 80 -resize 800 800 -l C:\filelist.txt
-o "$%.jpg" takes the actual directory, but not the folder of the picture from the filelist.

In my opinion, a new option would be usefuel to add the folder without drive-letter?

-o filename : Output filename
Use # to specify position of numeric enumerator
Use % to specify source filename
Use $ to specify source folder "i.g.: C:\ABC\"
NEW: Use & to specify source folder (from filelist) without driveletter "i.g.: PIC\SubDir1\"

So the command with this new option -o "C:\TEST\&%.jpg" should save the convertetd pictures into the same directory-structure:

whats your opinion?
Thanks Tom.

Nom d'utilisateur? what does that mean? i don't know french.

Post by xxx »

hey, i have quite a solution for you. you may use the windows "for" command. ehh... this is not so pretty but it works. make sure all your pictures are in a directory that contains "_" character, and no other directories or files contain it. your filelist.txt would look like this:

Code: Select all

after you have prepared your filelist you may write the following process.bat batch file:

Code: Select all

@echo off
for /F "delims=_ tokens=1,2" %%i in (filelist.txt) do echo %%i %%j
this procedure reads every line in filelist.txt and splits into tokens. the "_" char is the splitting character (delims=_). so in line 1 token 1 is F:\a and token 2 is a\stitlehl-100.png. token 1 goes to %%i and token 2 goes to %%j. therefore you may replace echo %%i %%j with nconvert ... -o someotherdirectory\%%j %%i_%%j
ehm... there is still one problem... nconvert doesn't convert the file if the destination directory doesnt exist.... this code should solve all:

Code: Select all

@echo off
set dest=f:\c\
for /F "delims=_ tokens=1,2" %%i in (filelist.txt) do call :convert "%%i_%%j" "%dest%%%j"
goto :eof

if not exist %~dp2 mkdir %~dp2
nconvert -out jpeg -o %~dpn2.jpg %~1
goto :eof
set dest=directory - set the destination folder
call :convert "%%i_%%j" "%dest%%%j" - call convert subroutine. we give this procedure parameters:
%1 will be F:\a_a\stitlehl-100.png
%2 will be F:\c\a\stitlehl-100.png
%~dp2 stands for "drive letter" and "path" from paramter 2 so
%~dp2 will be F:\c\a
finally, we want to convert it to jpeg but %2 has png extension. so we write %~dpn2.jpg
goto :label means jump to label. but goto :eof (end of file) means return from subroutine or exit program
you will find details of for, if and other commands in you windows help. type "for command" in the search box...
Posts: 40
Joined: Wed Mar 22, 2006 1:08 pm

Post by tom*de »

Thanks a lot xxx.

Now, I'm looking for a solution with Total-Commander-buttons (List.txt is created by TC and will contains the marked files):

This converts Pictures in List.txt to the source Directory ($):

Code: Select all

nconvert -keepfiledate -resize 220 220 -ratio -q 80 -text_font Verdana 10 -text_color 100 100 100 -text_flag bottom-left -text_pos 5 0 -text "2008" -out jpeg -o "$%_conv.jpg" -L "C:\List.txt"
How can I create a new target directory tree by using the source path of every path-entry from the source file list? E.g. Destination path should start with C:\PIC_CONV\ and than it should contains the source path every entry in List.txt:

C:\PIC\a.jpg should converted to C:\PIC_CONV\a.jpg
C:\PIC\2\a.jpg should converted to C:\PIC_CONV\2\a.jpg
Post Reply