3

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!

0

1 Answer 1

2
 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...

Sign up to request clarification or add additional context in comments.

3 Comments

Its working fine, but when im running the same script again it prompts "the file is already exists". If it is exists I want to replace, What I need to add
That would be on the :unzipfile subroutine which you haven't shown.
thanks @Magoo, its working fine, but while extracting I also want to hide the copying window , Is there a way to hide this using our batch script ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.