2

I'm attempting to zip up a folder with everything inside except for a single document, then output that compressed folder to a new location. However, when I do so, I get a Remove-Item error

Remove-Item : Cannot find path 'C:\Folder\123\12345\12345-A.zip' because it does not exist.
At C:\windows\system32\windowspowershell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:233 char:21
+ ...             Remove-Item -LiteralPath $DestinationPath -Force -Recurse ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Folder...12345\12345-A.zip:String) [Remove-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand

I don't have Remove-Item anywhere in my code, and the error appears to originate from an internal PowerShell module, only I can't figure out what caused it.

Unfortunately I'm in a position where I can't readily download alternative compressing libraries, as suggested in this thread.

Here is the relevant code:

Copy-Item -path $path -destination "$destination\$doc_project_folder\$doc_project_rev\"
Write-Host "Copied to $destination\$doc_project_folder\$doc_project_rev"
Get-ChildItem $document_hash[$doc] | Where { $_.Name -notin $docs_to_exclude} | 
              Compress-Archive -DestinationPath "$destination\$doc_project_folder\$doc_project_rev\$doc_number.zip" -compressionlevel fastest

This error is preventing me from successfully outputting the compressed folder to my desired location. What is causing this error, and/or what should I change to solve it?

gsamerica
  • 153
  • 1
  • 3
  • 18

1 Answers1

0

In my case, using the Expand-Archive led to exactly the same Remove-Item error. This code was throwing the error:

Expand-Archive $zipFileName -DestinationPath $targetFolder

After experimenting a bit, it turned out that adding the -Force parameter solves the problem:

Expand-Archive $zipFileName -DestinationPath $targetFolder -Force

Manually checking the extracted archive confirmed that it was correctly extracted.

I still do not know what causes the issue, which bugs me a bit. But adding the -Force parameter solved the issue in my case. Maybe it will work in your case as well.

ironcev
  • 382
  • 3
  • 15