# two parameter: the dest dir to be unzipped, the src zip file name, also in dest dir # if exists a folder or file of same name in zipped archieve, it will be deleted. function unzip([string] $path, [string]$zipFile) { if (!(test-path -path $zipFile)) { return $false; } if ((get-item -path $zipFile).length -eq 0) { return $false; } $shell=new-object -com shell.application; $ZipFolder = $shell.namespace("$ZipFile"); # make sure the path is created if (!(test-path -path $path)) { mkdir $path | out-null; } else { foreach ($srcItem in $ZipFolder.Items()) { $dstItemPath = join-path -path $path -childpath $srcItem.path; $exists = Test-Path -Path $dstItemPath; if ($exists) # If the item doesn't exist in the desination directory... { Remove-Item -Path $dstItemPath -Recurse; } } } $destinationFolder=$shell.namespace("$path"); $destinationFolder.Copyhere($ZipFolder.items()); return $true; } # two parameter: the source dir to be zipped, the dst zip file name which will be deleted if exists. function zip([string] $path, [string] $zipFile) { # make sure the path is created #echo "path=$path,zipFile=$zipFile" if (!(test-path -path $path)) { return $false; } if ((get-childitem -path $path) -eq $null) { return $false; } # make sure no zip file does NOT exists, because the UI need human interaction if (test-path -path $zipFile) { Echo "removing..." ### becareful!!! PS is really stupid to handle files!! # you need to clear content, not to remove the file!!!!!!!!!! #remove-item -path $zipFile -force; clear-content -path $zipFile; } else { new-item -path $zipFile -type "file" | out-null; } set-content $zipFile ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)); $src=get-item $path; $shell=new-object -com shell.application; $dst = $shell.namespace("$zipFile"); $dst.Synchronize(); foreach ($item in $src) { $dst.Copyhere($item.fullname); #$dst.Synchronize(); } #$dst.Synchronize(); start-sleep 3 return $true; }