Unzip file from source to destination within user directory across multiple versions of windows

batchshell-scriptzip

I have a source zip file which is located in a user's "My Documents" directory. It is guaranteed to always be there. I'm looking for a way to create a batch or script which will let me unzip that file to a destination directory also within the user's directory. If the destination is already there, it should first delete the existing destination folder.

Example process:

srcFile = %user%\My Documents\file.zip
destFolder = %user%\My Documents\Unzipped\
if destFolder exists, delete it
unzip srcFile to destFolder

I'm looking for a solution that will work on Windows XP and Windows 7. If possible, I don't want to use a zip application other than the one built into Windows XP/7.

Best Answer

DelUnzip.cmd:

RD /S /Q "%USERPROFILE%\My Documents\Unzipped"
cscript UnzipZip.vbs

UnzipZip.vbs:

strZipFile  = "\file.zip"
strUnzipped = "\Unzipped\"

Sub UnZip(ExtractTo,ZipFile)

Set fso = CreateObject("Scripting.FileSystemObject") 
    If NOT fso.FolderExists(ExtractTo) Then 
       fso.CreateFolder(ExtractTo) 
End If 

Set objShell = CreateObject("Shell.Application") 
Set FilesInZip=objShell.NameSpace(ZipFile).items 

ObjShell.NameSpace(ExtractTo).CopyHere(FilesInZip) 
Set fso = Nothing 
Set objShell = Nothing 
End Sub

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("MyDocuments")

strZipPath   = strDesktop & strZipFile
strUnzipPath = strDesktop & strUnzipped

UnZip strUnzipPath , strZipPath