windowsbatch-filespritebatch

how to pass arguments to a batch file


I have a batch file to unzip a file, the path of the zip file and destination folder is hardcoded. I want to unzip different zip files to different folders. I don't want to edit the code all the time, Please some one help on this.

 @echo off
 setlocal
 cd /d %~dp0
 Call :UnZipFile "G:\tett\" "G:\test\test.zip"
 pause
 exit /b

This is my batch file, here I am giving the paths of the source and destination. I want to pass the source and destination as arguments to run this batch. Thanks in Advance!


Solution

  •  Call :UnZipFile "%~1" "%~2"
    

    will call the :unzipfile routine passing two parameters as supplied to the batchfile, so from the prompt,

    yourbatchfile "parameter1" "parameter2"

    will accept the two parameters and deliver them to the :unzipfile routine.

    The parameters only need "quotes" if they contain separators line Space

    %~1 means "remove the enclosing quotes (if they exist) from the first parameter.

    I'll let you guess what %~2 means...