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!

Pyd
  • 6,017
  • 18
  • 52
  • 109

1 Answers1

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

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • 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 – Pyd Oct 17 '17 at 05:16
  • That would be on the `:unzipfile` subroutine which you haven't shown. – Magoo Oct 17 '17 at 07:50
  • 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 ? – Pyd Oct 19 '17 at 07:23