Announcement

Collapse
No announcement yet.

Batch conversion including all sub directories

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

    Batch conversion including all sub directories

    Hello,

    I want to convert BMP files to JPG - that's no problem, of course.
    Code:
    "%ProgramFiles%\IrfanView\i_view32.exe" c:\MainFolder\*.bmp /convert=c:\MainFolder\*.jpg /jpgq=85
    What I need, is to batch convert thousend of .bmp files from a source directory including multiple subdirectories (containing about 15-25 .bmp files each). At the end I would have the same folder structure but with .jpg files instead .bmp files. Subfolders structure is changing from day to day - based on current date.

    Any chance someone could help me with this?

    Thank you!

    #2
    Use the /advancedbatch option to apply Advanced Batch Dialog options to image (from INI file). In the Advanced Batch Operations dialogue you can set the option to recreate the directory structure in the destination folder.
    Before you post ... Edit your profile • IrfanView 4.62 • Windows 10 Home 19045.2486

    Irfan PaintIrfan View HelpIrfanPaint HelpRiot.dllMore SkinsFastStone CaptureUploads

    Comment


      #3
      Thanks for prompt reply

      The thing is that I do not know how .ini file should look like, how to recreate directory structure, can you give me some sample .ini file and commant line (.bat file) or link. Everything needs to be done via .bat file without direct using of IrfanView Application.

      Thank You

      Comment


        #4
        When you use the options that you want, then the INI file is updated. You can also specify the INI file to be used in the command line, to make sure it is not changed by using for another task.
        Before you post ... Edit your profile • IrfanView 4.62 • Windows 10 Home 19045.2486

        Irfan PaintIrfan View HelpIrfanPaint HelpRiot.dllMore SkinsFastStone CaptureUploads

        Comment


          #5
          so it should look like
          Code:
          %ProgramFiles%\IrfanView\i_view32.exe"  /advancedbatch /ini="C:\test.ini\" /convert="*.jpg"
          ?
          not working this way

          Comment


            #6
            Not working at all, or just not creating the subdirectories? The line for that in the INI file is

            AdvSubdirs=1

            What's the dot for in your INI file path c:\test.ini\ ?
            Do you need to quotes around filename "*.jpg"
            Before you post ... Edit your profile • IrfanView 4.62 • Windows 10 Home 19045.2486

            Irfan PaintIrfan View HelpIrfanPaint HelpRiot.dllMore SkinsFastStone CaptureUploads

            Comment


              #7
              None of this is going to work because most Miscellaneous Advanced Batch options are not supported in the command line like overwrite, delete, subfolders, and all pages.

              Comment


                #8
                IrfanView's Batch Conversion dialog will definitely make your job easier, but I think you might be interested in this batch file:

                Code:
                @echo off
                "%ProgramFiles%\IrfanView\i_view32.exe" /jpgq=85 /killmesoftly
                xcopy /i /q /s /y "C:\Main\*.bmp" "C:\MainJPG"
                set Source=C:\MainJPG
                for /F "tokens=* delims=" %%a in ('dir /ad /b /s "%Source%"') do call :Sub "%%a"
                del /s "%Source%\*.bmp"
                goto :eof
                
                :Sub
                "%ProgramFiles%\IrfanView\i_view32.exe" "%~1\*.bmp" /convert="%~1\*.jpg"
                goto :eof
                Be sure to test this out first. Basically, it places the converted files in a folder named MainJPG with the same folder structure as Main.

                If you want the converted files to be placed in the same subfolders as the BMP files I can either give you a different BAT file or you can simply copy the subfolders from MainJPG to Main. You could also use a BAT file that places the converted files into Main with similar named subfolders. You could also create a BAT file using custom commands that you generate in a spreadsheet. This requires more intervention, but might give you more control unless a better BAT file surfaces. You could input the paths generated in this BAT:

                Code:
                dir "C:\Main" /ad /b /s > "C:\list.txt"
                "C:\list.txt"
                and output to a batch file like this:

                Code:
                "%ProgramFiles%\IrfanView\i_view32.exe" /jpgq=85 /killmesoftly
                "%ProgramFiles%\IrfanView\i_view32.exe" "C:\Main\Coupes\*.bmp" /convert="C:\Main\Coupes\*.jpg"
                "%ProgramFiles%\IrfanView\i_view32.exe" "C:\Main\Convertibles\*.bmp" /convert="C:\Main\Convertibles\*.jpg"
                "%ProgramFiles%\IrfanView\i_view32.exe" "C:\Main\Sedans\*.bmp" /convert="C:\Main\Sedans\*.jpg"
                As you can see, the BMP subfolders could be the destination for the JPGs or you could modify the destination to something else to sort the files.

                Comment


                  #9
                  Thank you all for the help!
                  Skippybox, with some modification it's exactly what I need
                  Code:
                  "%ProgramFiles%\IrfanView\i_view32.exe" /jpgq=85 /killmesoftly
                  set Source=C:\MainDir
                  for /F "tokens=* delims=" %%a in ('dir /ad /b /s "%Source%"') do call :Sub "%%a"
                  del /s "%Source%\*.bmp"
                  goto :eof
                  :Sub
                  "%ProgramFiles%\IrfanView\i_view32.exe" "%~1\*.bmp" /convert="%~1\*.jpg"
                  goto :eof
                  2 more things:
                  1. .bmp files in 'MainDir' are not converted, only bmp's in MainDir/Subfolders/ are.
                  2. another thing I need is to save converted files with original date/time
                  I tried with /advancedbatch /ini="C:\MainDir\" with the
                  Code:
                  [Batch]
                  UseAdvanced=1
                  AdvSaveOldDate=1
                  in the C:\MainDir\i_view32.ini , but I'm getting this error: 'Can't read files header. Unknown file format or file not found'
                  Conversion is working anyway, but it can't read ini file and date/time of converted files are not original.

                  Comment


                    #10
                    Hello Ivan

                    From your code it appears that you do want the JPGs in the same folders as the BMPs. Do you indeed want the original BMPs deleted, too?

                    Originally posted by Ivan View Post
                    1. .bmp files in 'MainDir' are not converted, only bmp's in MainDir/Subfolders/ are.
                    It wasn't clear in your original post that you needed that. I figured you could do that via the command line if necessary. Nonetheless, I've easily added that capability to the batch file.

                    2. another thing I need is to save converted files with original date/time
                    I tried with /advancedbatch /ini="C:\MainDir\" with the
                    Code:
                    [Batch]
                    UseAdvanced=1
                    AdvSaveOldDate=1
                    in the C:\MainDir\i_view32.ini , but I'm getting this error: 'Can't read files header. Unknown file format or file not found'
                    Conversion is working anyway, but it can't read ini file and date/time of converted files are not original.
                    You're syntax appears correct (although UseAdvanced=1 is not necessary), but it looks like you placed it in the wrong place in the batch file. I suspect you placed it in this part:

                    Code:
                    "%ProgramFiles%\IrfanView\i_view32.exe" /jpgq=85 /advancedbatch /ini="C:\MainDir\" /killmesoftly
                    This line does not perform a conversion, therefore it would wonder where the file is you are trying to convert. I've decided to eliminate that line since you will be using an ini. The new ini (keep it in C:\MainDir) will contain the /jpgq value now and appear as so:

                    Code:
                    [JPEG]
                    Save Quality=85
                    [Batch]
                    AdvSaveOldDate=1
                    Remember, any items absent from the custom ini will use default values, not the values present in the program ini.

                    Although your invalid code throws an error, it would not affect conversion as you say, but of course it would not use your ini. Thus, the date/time would not be original.

                    I've altered the code a bit to adjust for these things and match your apparent preferrences. Also, I included a check for the BMPs to make sure you don't get an error if there are none. This also will quickly stop the script if there is nothing to do. Here it is:

                    Code:
                    @echo off
                    set Source=C:\MainDir
                    for /F "tokens=* delims=" %%a in ('dir /ad /b /s "%Source%"') do call :Sub "%%a"
                    if exist "%Source%\*.bmp" ("%ProgramFiles%\IrfanView\i_view32.exe" "%Source%\*.bmp" /advancedbatch /ini="%Source%" /convert="%Source%\*.jpg")
                    del /s "%Source%\*.bmp"
                    goto :eof
                    
                    :Sub
                    if exist "%~1\*.bmp" ("%ProgramFiles%\IrfanView\i_view32.exe" "%~1\*.bmp" /advancedbatch /ini="%Source%" /convert="%~1\*.jpg")
                    goto :eof
                    Be sure to test it out first. Enjoy!
                    Last edited by Skippybox; 16.10.2008, 10:20 PM.

                    Comment


                      #11
                      Thank you, perfect
                      I changed some code - user input required for the source path :
                      Code:
                      cls
                      @echo off
                      
                      :convert
                      set /p DRIVE=Choose Partition (c,d,e,f,...)
                      echo.
                      set /p NAME=Choose Folder:
                      
                      "%ProgramFiles%\IrfanView\i_view32.exe" /killmesoftly
                      
                      if not exist %DRIVE%:\%NAME% goto tema
                      set Source=%DRIVE%:\%NAME%
                      
                      for /F "tokens=* delims=" %%a in ('dir /ad /b /s "%Source%"') do call :Sub "%%a"
                      if exist "%Source%\*.bmp" ("%ProgramFiles%\IrfanView\i_view32.exe" "%Source%\*.bmp" /advancedbatch /ini="%Source%" /convert="%Source%\*.jpg") 
                      
                      del /s "%Source%\*.bmp"
                      goto :eof
                      
                      :Sub
                      if exist "%~1\*.bmp" ("%ProgramFiles%\IrfanView\i_view32.exe" "%~1\*.bmp" /advancedbatch /ini="%Source%" /convert="%~1\*.jpg") 
                      goto :eof
                      
                      :tema
                      @echo ----------------------------------------
                      echo Folder %DRIVE%:\%NAME% does not exist
                      @echo ----------------------------------------
                      echo.
                      set /p znovabine=Try Again (y,n):
                      if "%znovabine%"=="y" goto convert
                      if "%znovabine%"=="n" goto exit
                      
                      :exit
                      exit
                      the thing is that I have problems in case folder name is 'Batch SomeFolder' and not 'BatchSomeFolder', I'm getting some error like ' SomeFolder is not recognized as command ...'

                      Comment


                        #12
                        The problem was in your code:

                        Code:
                        if not exist %DRIVE%:\%NAME% goto tema
                        Whenever spaces are involved, you need quotes, like this:

                        Code:
                        if not exist "%DRIVE%:\%NAME%" goto tema
                        That is why a folder like 'BatchSomeFolder' would get accepted and a folder named 'Batch SomeFolder' would not. It was trying to interpret the part after the space, 'SomeFolder' as a command and couldn't.

                        I made the adjustment in the code below as well as a few others. I swapped your lines since %Source% could already refer to %DRIVE%:\%NAME%. Also, you were still using "%ProgramFiles%\IrfanView\i_view32.exe" /killmesoftly even though it is completely unnecessary as I stated before. So that is removed.

                        Code:
                        cls
                        @echo off
                        
                        :convert
                        set /p DRIVE=Choose Partition (c,d,e,f,...)
                        echo.
                        set /p NAME=Choose Folder:
                        
                        set Source=%DRIVE%:\%NAME%
                        if not exist "%Source%" goto tema
                        
                        for /F "tokens=* delims=" %%a in ('dir /ad /b /s "%Source%"') do call :Sub "%%a"
                        if exist "%Source%\*.bmp" ("%ProgramFiles%\IrfanView\i_view32.exe" "%Source%\*.bmp" /advancedbatch /ini="%Source%" /convert="%Source%\*.jpg") 
                        
                        del /s "%Source%\*.bmp"
                        goto :eof
                        
                        :Sub
                        if exist "%~1\*.bmp" ("%ProgramFiles%\IrfanView\i_view32.exe" "%~1\*.bmp" /advancedbatch /ini="%Source%" /convert="%~1\*.jpg") 
                        goto :eof
                        
                        :tema
                        @echo ----------------------------------------
                        echo Folder %DRIVE%:\%NAME% does not exist
                        @echo ----------------------------------------
                        echo.
                        set /p znovabine=Try Again (y,n):
                        if "%znovabine%"=="y" goto convert
                        if "%znovabine%"=="n" goto exit
                        
                        :exit
                        exit
                        Skippybox

                        Comment

                        Working...
                        X