Announcement

Collapse
No announcement yet.

Command Line Batch Resize and rename

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Command Line Batch Resize and rename

    I am currently trying to resize and rename a collection of jpgs using the following command line:

    i_view32.exe c:\savers\jpg\*.jpg /resize=(800,600) /convert=c:\savers\bmp\PICT#.bmp

    It converts the files like it should but keeps overwriting each other and I always end up with one file in C:\savers\bmp: "PICT#.bmp"

    How do I get the "#" in "PICT#.bmp" to increment with each file it resizes?

    #2
    Use a batch script like the following.


    Example:
    @echo off
    cls
    setlocal

    :: --- Configuration --->

    :: Path to IrfanView
    set iview=E:\IrfanView\i_view32.exe

    :: Source path
    set source=H:\Meine Photos\jpg

    :: Target path
    set target=H:\Meine Photos\bmp

    :: File name
    set prefix=PICT

    :: Suffix of the source files
    set ssuffix=jpg

    :: Suffix of the target files
    set tsuffix=bmp

    :: Start index of the counter
    set index=1

    :: Addition value of the counter
    set step=1

    :: Leading zeros of the counter (delete value for no leading zeros)
    set zeros=000

    :: <--- Configuration ---

    for %%a in ("%source%\*.%ssuffix%") do call :CONVERT "%%a"
    goto ENDE

    :CONVERT
    set number=%zeros%%index%
    set number=%number:~-4%
    echo %~1
    "%iview%" %1 /resize=(200,100) /convert="%target%\%prefix%%number%.%tsuffix%"
    set /a index=%index% + %step%
    goto :EOF

    :ENDE

    endlocal
    »Und so, in eurer Verzweiflung, kommt ihr zu mir.«

    Texteditor EmEditor:
    Deutsche Sprachdatei (v7.01) für EmEditor Pro 7.02 (englisch)
    EmEditor Pro 8.06 (deutsch) | Deutsche Sprachdatei (v8) für EmEditor Pro 8.06 (englisch)
    Deutsche Sprachdatei (v9.16) für EmEditor Pro 9.17 (englisch)

    Comment


      #3
      Originally posted by ckiley28 View Post
      I am currently trying to resize and rename a collection of jpgs using the following command line:
      i_view32.exe c:\savers\jpg\*.jpg /resize=(800,600) /convert=c:\savers\bmp\PICT#.bmp
      It converts the files like it should but keeps overwriting each other and I always end up with one file in C:\savers\bmp: "PICT#.bmp"
      How do I get the "#" in "PICT#.bmp" to increment with each file it resizes?
      AFAIK Irfanview cannot put an incrementing count into the file name using a simple, single command line such as this. You do need to use a batch script such as the one Foxy has posted to generate the number for you. The usual way of using the * option in the input filename is to put one in the output filename too e.g /convert=c:\savers\bmp\*.bmp
      Each output file will then have the same name as the input one but with a .bmp suffix instead of .jpg
      The nearest you can get to a count is to put a placeholder for the index number of the input file into the pattern e.g /convert=c:\savers\bmp\PICT$X.bmp
      That will give you output filenames such as ...., PICT[2_30].bmp , PICT[3_30].bmp , .... etc.

      I assume that there is some reason for not opening Irfanview and using the built in Batch Conversion and Rename feature. That can rename with an incrementing count number in the filename.
      Last edited by Mij; 24.07.2010, 06:31 PM.

      Comment


        #4
        Foxy,

        That is exactly what I needed. Thank you very much!!!!

        Mij - I am trying to automate a process like you said.

        Thanks for the feedback guys!

        Comment

        Working...
        X