Batch script

Because MultiPar consists of PAR clients and GUI, it is possible to use a PAR client from DOS prompt (command prompt in Windows 2000/XP). Read a manual of command line to the details of command and option. It is available by batch file (command script in Windows 2000/XP), too.

Below are some samples of batch file for Windows 2000/XP. Copy & paste the whole lines into a text file. Modify the options for PAR2 files, and set the path of par2j.exe. Write absolute path like;
SET par2_path="C:\something directory\MultiPar\par2j.exe"
Read manuals (Command_***.txt) to know the detail of options. Read Windows OS 's help for command line usage and detail.

Save a sample script to a file like "batch.bat" or "batch.cmd". To specify path of files or folders, Drag & Drop them on the batch file. When you put a shortcut icon of the batch file in "SendTo" menu, you can call the batch file by selecting files then Righ-Click & SendTo.


Index

Create individual PAR2 set in each selected folder (with GUI)  
Create individual PAR2 set in each sub-folder under a selected folder  
Create one PAR2 file per each file in a selected folder  
Create individual PAR2 set per each set of 4 files from many selected files  
Create PAR2 recovery data and append it to each original ZIP / 7-Zip archive file  

Verify and/or Repair individual PAR2 set in each selected folder with GUI  

Add MD5 checksum to each file independently in a selected folder (NTFS only)  
Verify each file independently by MD5 checksum in a selected folder (NTFS only)  

Play sound for notification  

Batch script after MultiPar GUI 's Creation  
Batch script after MultiPar GUI 's Verification / Repair  

Create individual PAR2 set in each selected folder (with GUI)

command "path of batch file" "path of folder1" "path of folder2" "path of folder3"...
input specify some folders
action This sample creates individual PAR2 set in each selected folder. For example, when you supply 7 folders, total 7 PAR2 set are made. It is possible to show GUI for setting, too.
@ECHO OFF
SETLOCAL
SET par2_path="path of par2j.exe"
:GetFilePath
REM check input path
IF "%~1"=="" GOTO End
IF NOT EXIST "%~1" GOTO NextFile
IF NOT "%~z1"=="0" GOTO NextFile
REM run PAR2 client
ECHO create for %1
%par2_path% c /sm2048 /rr20 /rd1 /rf3 "%~1\%~n1.par2" *
IF ERRORLEVEL 1 GOTO End
:NextFile
SHIFT
GOTO GetFilePath
:End
ENDLOCAL

If you want to use MultiPar GUI for setting, you may call MultiPar.exe instead of par2j.exe. When a GUI is closed, next GUI is opened with next folder. You may set an option in "Automated tasks" to close GUI automatically after creation.

@ECHO OFF
SETLOCAL
SET multipar_path="path of MultiPar.exe"
:GetFilePath
REM check input path
IF "%~1"=="" GOTO End
IF NOT EXIST "%~1" GOTO NextFile
IF NOT "%~z1"=="0" GOTO NextFile
REM open MultiPar GUI
ECHO create for %1
%multipar_path% /create %1
:NextFile
SHIFT
GOTO GetFilePath
:End
ENDLOCAL

Create individual PAR2 set in each sub-folder under a selected folder

command "path of batch file" "path of a folder"
input specify a folder
action This sample creates individual PAR2 set in each sub-folder under the selected folder. For example, when there are 7 sub-folders, total 7 PAR2 set are made.
@ECHO OFF
SETLOCAL
REM check input path
IF "%~1"=="" GOTO End
IF NOT EXIST "%~1" (
ECHO The path does not exist.
GOTO End
)
IF NOT "%~z1"=="0" GOTO End
REM set options for PAR2 client
SET par2_path="path of par2j.exe"
REM recursive search of sub folders
PUSHD %1
FOR /D /R %%G IN (*.*) DO CALL :ProcEach "%%G"
POPD
GOTO End
REM run PAR2 client
:ProcEach
ECHO create for %1
%par2_path% c /fo /sm2048 /rr20 /rd1 /rf3 "%~1\%~n1.par2" *
GOTO :EOF
:End
ENDLOCAL

Don't remove an option /fo in the command-line. By this option, PAR2 file contains files only in each sub-folder.


Create one PAR2 file per each file in a selected folder

command "path of batch file" "path of a folder"
input specify a folder
action This sample creates one PAR2 file per each file in the selected folder. If there is a sub-folder in a folder, files in the sub-folder are searched, too. Instead of creating PAR2 files for all files in a sub-folder like previous sample, this creates one PAR2 file per each file in a sub-folder. For example, when there are 7 files in the folder, total 7 PAR2 files are made.
@ECHO OFF
SETLOCAL
REM check input path
IF "%~1"=="" GOTO End
IF NOT EXIST "%~1" (
ECHO The path does not exist.
GOTO End
)
IF NOT "%~z1"=="0" GOTO End
REM set options for PAR2 client
SET par2_path="path of par2j.exe"
REM recursive search of files
PUSHD %1
FOR /R %%G IN (*.*) DO CALL :ProcEach "%%G"
POPD
GOTO End
REM run PAR2 client
:ProcEach
ECHO create for %1
%par2_path% c /fo /sm2048 /rr10 /ri /in /lr32767 "%~1.par2" %1
GOTO :EOF
:End
ENDLOCAL

  Don't remove an option /in in the command-line. By this option, index file isn't created.


Create individual PAR2 set per each set of 4 files from many selected files

command "path of batch file" "path of file1" "path of file2" "path of file3" "path of file4" "path of file5"...
input specify many files
action This sample creates individual PAR2 set per each set of 4 files from many selected files. For example, when you supply 11 files, total 3 PAR2 set are made. (11 = 4 + 4 + 3)
@ECHO OFF
SETLOCAL
REM set options for PAR2 client
SET par2_path="path of par2j.exe"
SET /a N=1
:GetFilePath
REM check input path
IF "%~1"=="" GOTO End
IF NOT EXIST "%~1" GOTO End
REM run PAR2 client
ECHO create for "%~d1%~p1par_set%N%"
%par2_path% c /sm2048 /rr20 /rd1 /rf3 "%~d1%~p1par_set%N%.par2" %1 %2 %3 %4
SET /a N=N+1
SHIFT
SHIFT
SHIFT
SHIFT
GOTO GetFilePath
:End
ENDLOCAL

You may modify this sample to accept more files up 9. Be careful about the number of source files and SHIFT per each step.


Create PAR2 recovery data and append it to each original ZIP / 7-Zip archive file

command "path of batch file" "path of archive file1" "path of archive file2" "path of archive file3"...
input specify some ZIP / 7-Zip archive files
action This sample creates PAR2 recovery data and append it to each original ZIP / 7-Zip archive file. Though ZIP / 7-Zip archive don't have a feature of recovery record, parchive can add the extra feature. For example, when you supply 7 archive files, total 7 archive files with recovery record are made.
@ECHO OFF
SETLOCAL
REM set options for PAR2 client
SET par2_path="path of par2j.exe"
:GetFilePath
REM check input path
IF "%~1"=="" GOTO End
IF NOT EXIST "%~1" GOTO End
IF "%~z1"=="0" GOTO NextFile
REM check format
IF /i "%~x1" NEQ ".zip" (
IF /i "%~x1" NEQ ".7z" (
GOTO NextFile
)
)
REM ignore already appended file
%par2_path% l %1
IF NOT ERRORLEVEL 1 GOTO NextFile
REM run PAR2 client
ECHO append to %1
%par2_path% c /fo /sm2048 /rr10 /ri /in /lr32767 /lp4 "%~1.par2" %1
REM join 2 files
COPY /b "%~1"+"%~1.vol_1.par2" /v "%~1"
DEL "%~1.vol_1.par2"
:NextFile
SHIFT
GOTO GetFilePath
:End
ENDLOCAL

Don't remove options /ri and /in in the command-line. By this option, index file isn't created and filename has fixed volume number. When joinning original archive and recovery data, it is important to put original archive at first, then append recovery data at the last. From the nature of ZIP / 7-Zip archive, appended PAR2 recovery data has no effect to extract or decompress. If you want to keep PAR2 file separately, comment out the line of DEL command.

To verify the archive, just Drag&Drop it onto MultiPar short-cut icon. (or right-click SendTo or ShellExtension works, too.) On the MultiPar GUI, the archive with PAR2 recovery data is shown as "Appended" status, when the original part of archive is complete. If you repair the archive, the archive returns to the original form. (appended PAR2 recovery data is removed.) When you want to keep the PAR2 recovery data, you need to un-check an option "Delete damaged files after Repair". Then the recovery data is renamed by adding ".1" after filename.


Verify and/or Repair individual PAR2 set in each selected folder with GUI

command "path of batch file" "path of folder1" "path of folder2" "path of folder3"...
input specify some folders
action This sample call MultiPar GUI for individual PAR2 set in each selected folder. For example, when you supply 7 folders, GUI are opened 7 times one by one. It is possible to repair by the GUI. When a GUI is closed, next GUI is opened with next PAR2 set.
@ECHO OFF
SETLOCAL
SET multipar_path="path of MultiPar.exe"
:GetFilePath
REM check input path
IF "%~1"=="" GOTO End
IF NOT EXIST "%~1" GOTO NextFile
IF NOT "%~z1"=="0" GOTO NextFile
REM open MultiPar GUI
ECHO verify for %1
%multipar_path% /verify "%~1\%~n1.par2"
:NextFile
SHIFT
GOTO GetFilePath
:End
ENDLOCAL

The key is setting the PAR filename to be based on the folder name. If you set prefix/suffix to filename at creating time, you need to set same one at verifying time.


Add MD5 checksum to each file independently in a selected folder (NTFS only)

command "path of batch file" "path of a folder"
input specify a folder
action This sample adds MD5 checksum to each file independently in a selected folder. If there is a sub-folder in a folder, files in the sub-folder are searched, too. This uses "Alternate Data Stream" and works over NTFS only. Checksum data is saved in an alternate stream "original filename:digest.md5", but it's invisible by Windows Explorer.
@ECHO OFF
SETLOCAL
REM check input path
IF "%~1"=="" GOTO End
IF NOT EXIST "%~1" (
ECHO The path does not exist.
GOTO End
)
IF NOT "%~z1"=="0" GOTO End
REM set options for SFV/MD5 client
SET client_path="path of sfv_md5.exe"
REM recursive search of files
PUSHD %1
FOR /R %%G IN (*.*) DO CALL :ProcEach "%%G"
POPD
ECHO Finished to add checksums into alternate stream.
PAUSE
GOTO End
REM run SFV/MD5 client
:ProcEach
ECHO create for %1
%client_path% c "%~1:digest.md5" %1
IF ERRORLEVEL 1 (
ECHO Stop at this point.
PAUSE
EXIT
)
GOTO :EOF
:End
ENDLOCAL

There are some cautions. Some binary/text editor seems to remove alternate data stream automatically at over-writing. If you modify a file, you will need to re-add checksum to the new file again. Adding checksum will update files' modification time, even though original file data isn't changed. A user needs to use a special tool to see/delete/copy the stream, because those streams are untouchable by Windows Explorer. While an alternate stream is kept at copy/move between NTFS drives, it will be removed on other file system. For example, you cannot backup data in alternate stream on CD/DVD.


Verify each file independently by MD5 checksum in a selected folder (NTFS only)

command "path of batch file" "path of a folder"
input specify a folder
action This sample verify each file independently by MD5 checksum in a selected folder. If there is a sub-folder in a folder, files in the sub-folder are searched, too. This uses "Alternate Data Stream" and works over NTFS only. Checksum data must have been saved in an alternate stream "original filename:digest.md5".
@ECHO OFF
SETLOCAL
REM check input path
IF "%~1"=="" GOTO End
IF NOT EXIST "%~1" (
ECHO The path does not exist.
GOTO End
)
IF NOT "%~z1"=="0" GOTO End
REM set options for SFV/MD5 client
SET client_path="path of sfv_md5.exe"
REM recursive search of files
PUSHD %1
FOR /R %%G IN (*.*) DO CALL :ProcEach "%%G"
POPD
ECHO Finished to verify files by checksums in alternate stream.
PAUSE
GOTO End
REM run SFV/MD5 client
:ProcEach
ECHO verify for %1
%client_path% v "%~1:digest.md5"
IF ERRORLEVEL 4 (
ECHO This file is broken.
PAUSE
GOTO :EOF
)
IF ERRORLEVEL 1 (
ECHO Stop at this point.
PAUSE
EXIT
)
GOTO :EOF
:End
ENDLOCAL

Play sound for notification

This sample plays sound by Sound Recoder. This is good to notify the end of process to user, while running script.

@ECHO OFF
SETLOCAL
REM set path of sound file
SET WAVPATH=%systemroot%\Media\The Microsoft Sound.wav
REM call Sound Recoder
sndrec32.exe /embedding /play /close %WAVPATH%
ENDLOCAL

This sample plays sound by Media Player. Because Sound Recoder cannot play sound on recent Windows OS, Media Player is used in this sample. This can play any file format which is supported by Media Player.

@ECHO OFF
SETLOCAL
REM set path of sound file
SET WAVPATH=%systemroot%\Media\The Microsoft Sound.wav
REM set playing time by mil seconds
SET HTA_MAX_TIME=5000
REM call HTA application (JavaScript and Media Player plag-in)
mshta.exe "about:playing... <OBJECT CLASSID='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' WIDTH=100 HEIGHT=100><param name='src' value='%WAVPATH%'><param name='PlayCount' value='1'><param name='autostart' value='true'></OBJECT><script>window.resizeTo(10,10);setTimeout(function(){window.close()},%HTA_MAX_TIME%);</script>"
ENDLOCAL

Batch script after MultiPar GUI 's Creation

MultiPar GUI can start script after creation. The script file must be "auto_c.cmd" in the user's "save" folder. A user may write any script in this file. The script gets two parameters from GUI as below;
%1 = Path of a recovery file
%2 = Path of base directory of source files

This sample script moves created PAR2 recovery files into another folder.

@ECHO OFF
TITLE After creation
SETLOCAL
REM List up parameters
ECHO Path of this batch file =
ECHO %0
ECHO.
ECHO Path of a recovery file =
ECHO %1
ECHO.
ECHO Path of base directory of source files =
ECHO %2
ECHO.
REM check the extension for .par2
IF NOT %~x1==.par2 (
ECHO The recovery file format is not PAR2.
GOTO End
)
REM insert * between filename and extension
SET search_path="%~d1%~p1%~n1*%~x1"
REM move all created recovery files into another folder
SET destination_folder="C:/Sample/"
ECHO Moving %search_path%
move %search_path% %destination_folder%
ECHO Above files were gone to %destination_folder%
:End
ENDLOCAL

Batch script after MultiPar GUI 's Verification / Repair

MultiPar GUI can start script after verification or repair. The script file must be "auto_v.cmd" in the user's "save" folder. A user may write any script in this file. The script gets three parameters from GUI as below;
%1 = Path of a recovery file
%2 = Path of base directory of source files
%3 = Exit code of the used client (refer the command-line manual)

This sample script opens ZIP or 7-Zip archive only when it is complete. To use this script, you need to create some recovery files for an archive at first. At that time, the key is setting the base filename to be same as the source file like;
source file's name = something.zip
recovery files' name = something.zip.par2, something.zip.vol0+4.par2, something.zip.vol4+8.par2
Thus, when you open the index file "something.zip.par2", the filename without last extension becomes the name of source file.

@ECHO OFF
TITLE After verification
SETLOCAL
REM List up parameters
ECHO Path of this batch file =
ECHO %0
ECHO.
ECHO Path of a recovery file =
ECHO %1
ECHO.
ECHO Path of base directory of source files =
ECHO %2
ECHO.
ECHO Status of source files = %3
ECHO.
REM check the source file is complete
IF NOT %3==0 (
IF NOT %3==16 (
ECHO The file is broken.
GOTO End
)
)
REM remove last extension from path
SET new_path="%~d1%~p1%~n1"
ECHO Target file = %new_path%
IF EXIST %new_path% (CALL :OpenFile %new_path%) ELSE ECHO The file does not exist.
GOTO End
:OpenFile
REM check the format and open the supported file
IF /i "%~x1" EQU ".zip" (
ECHO Open the ZIP archive
%1
GOTO :EOF
)
IF /i "%~x1" EQU ".7z" (
ECHO Open the 7-Zip archive
%1
GOTO :EOF
)
ECHO The file format is not supported.
GOTO :EOF
:End
ENDLOCAL