Here's my script (createdistro.ps1)
Add-Type -assembly "system.io.compression.filesystem"
$source = "bin\Debug\"
$destination = "gwtester_signed.zip"
If(Test-path $destination) {Remove-item $destination}
[io.compression.zipfile]::CreateFromDirectory($source, $destination)
Notice the error message I get from running the script:
PS C:\dev\DEV7\Test\gwtester> .\createdistro.ps1
Exception calling "CreateFromDirectory" with "2" argument(s): "The file 'C:\Users\bbren\gwtester_signed.zip' already
exists."
At C:\dev\DEV7\Test\gwtester\createdistro.ps1:7 char:1
+ [io.compression.zipfile]::CreateFromDirectory($source, $destination)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IOException
As you can see, the script attempts to write to C:\Users\bbren\gwtester_signed.zip
, but the current working directory is C:\dev\etc\
.
The documentation for ZipFile.CreateFromDirectory states that "A relative path is interpreted as relative to the current working directory."
What is wrong?