Announcement

Collapse
No announcement yet.

Batch file skeleton

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

    Batch file skeleton

    Hi there,

    here is a skeleton I'd like to use (copy and paste it into a text file and save it as a .cmd file:
    Code:
    @echo off
    rem **********************************
    rem * IrfanView script file skeleton *
    rem **********************************
    rem This file is a skeleton for IrfanView script files.
    setlocal
    
    rem ************
    rem * Settings *
    rem ************
    
    rem Path to Irfan view
    rem If IrfanView is installed in the common program files folder this part
    rem should be usable.
    rem If you have installed IrfanView elsewhere, i.e. in D:\Tools\IV then
    rem just delete these lines and uncomment and modify the set iview line.
    if /i "%PROCESSOR_ARCHITECTURE%" equ "AMD64" (
     rem Path to IrfanView on x64 Windows
     set iview="%ProgramFiles(x86)%\IrfanView\i_view32.exe"
    ) else (
     rem Path to IrfanView on x86 Windows
     set iview="%ProgramFiles%\IrfanView\i_view32.exe"
    )
    rem set iview="D:\tools\i_view32.exe"
    if not exist %iview% goto noIview
    
    rem Do something
    rem Put your functions here
    start "IrfanView" /wait %iview% <Parameters>
    
    rem After finishing go to the end
    goto end
    
    
    rem IrfanView could not be found.
    :noiview
    echo IrfanView not found in the given path:
    echo   %iview%
    goto end
    
    rem End of the script
    :end
    pause
    endlocal
    Feel free to use this as a base for your own scripts.

    Some explanations:
    set iview="%ProgramFiles%\IrfanView\i_view32.exe"
    This stores the path to the IrfanView executable in the variable iview. So the path has to be defined just once.
    The path needs to be modified if IrfanView is not installed in the default program files folder, since IrfanView does not need to be installed some users put it into a separate folder. So just remove the block and remove the "rem" of the line
    rem set iview="D:\tools\i_view32.exe"
    and modify the path. Please keep the double quotes if you are not sure for what they are needed for.

    Later in the script there is a line
    Code:
    start "IrfanView" /wait %iview% <Parameters>
    This is where your code should go.
    %iview% starts the IrfanView program file.

    In front there is
    Code:
    start "IrfanView" /wait
    This part will start an IrfanView instance and waits until the program is closed. Depending on the parameters this is done automatically or manually.

    So, have fun
    Nils
Working...
X