Checking Command Line Parameters in WINXP Batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jaffamuffin
Posts: 40
Joined: 25 Jan 2008 14:05

Checking Command Line Parameters in WINXP Batch

#1 Post by jaffamuffin » 25 Jan 2008 14:28

Hi all

Just wrote this batch file to check the command line params in a batch file I'm working on.

Posting here as a referance and in case it is useful for others. Or can anyone improve on it?

If anyone has any feedback that would be nice cheers.

Code: Select all

@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

SET InDir=X:\tobeprocessed
SET OutDir=X:\processed
SET tifDir=%OutDir%\tifs
SET jpgDir=%OutDir%\jpgs
SET bakDir=X:\BACKUP
SET JPGSZ=75
SET JPGQL=40
SET LOGDIR=X:\logs
SET BKTYP=1 2+3 4 5+6
SET AddZ=1
SET DEBUG=
SET VERB=1

ECHO Checking Commandline Parameters...
SET PARAMCOUNT=0
GOTO _processcmdline
GOTO:EOF


:_start
ECHO.
ECHO Using these values:
echo.INDIR      = %InDir%
echo.OUTDIR     = %OutDir%
echo.TIFDIR     = %tifDir%
echo.JPGDIR     = %jpgDir%
echo.BAKDIR     = %bakDir%
echo.LOGDIR     = %LOGDIR%
echo.IMGPROGRAM = %IMGCMD%
echo.JPGRESIZE  = %JPGSZ%
echo.JPGQUALITY = %JPGQL%
echo.BKTYP      = %BKTYP%
echo.ADDZ       = %AddZ%
echo.VERBOSITY  = %VERB%
ECHO Pause for 5 seconds...
ping -n 6 127.0.0.1 >NUL
ECHO Let's do it...
GOTO:EOF



:_processcmdline
IF "%1"=="/?" GOTO _syntax
IF "%1"=="-help" GOTO _help
SET FOUND=0
SET /A PARAMCOUNT=PARAMCOUNT+1
SET PARAMS=-q -v -vv -vvvv -imgcmd -jpg -resize -indir -outdir -bakdir -backdir -bakup -backup -logdir -addz -debug
FOR %%A IN (%PARAMS%) DO (
   IF "%1"=="%%A" SET FOUND=1
)
IF !FOUND!==0 (
   ECHO Unknown option: %1 at Parameter: !PARAMCOUNT!
   ECHO Possible spaces in directory paths or spelling error?
   GOTO:EOF
)
IF !FOUND!==1 ECHO Parameter OK: %1
IF "%1"=="-debug" SET DEBUG=PAUSE
IF "%1"=="-q" SET VERB=0
IF "%1"=="-v" SET VERB=2
IF "%1"=="-vv" SET VERB=3
IF "%1"=="-vvv" SET VERB=4
IF "%1"=="-imgcmd" SET IMGCMD=%2 & SHIFT
IF "%1"=="-jpg" SET JPGQL=%2 & SHIFT
IF "%1"=="-resize" SET JPGSZ=%2 & SHIFT
IF "%1"=="-indir" SET InDir=%2 & SHIFT
IF "%1"=="-outdir" SET OutDir=%2 & SHIFT
IF "%1"=="-bakdir" SET BakDir=%2 & SHIFT
IF "%1"=="-backdir" SET BakDir=%2 & SHIFT
IF "%1"=="-bakup" SET BakDir=%2 & SHIFT
IF "%1"=="-backup" SET BakDir=%2 & SHIFT
IF "%1"=="-logdir" SET LOGDIR=%2 & SHIFT
IF "%1"=="-addz" SET AddZ=%2 & SHIFT
SHIFT                               
IF "%1" == "" GOTO:_start       
GOTO _processcmdline

Post Reply