Compress-Archive with hidden items

Welcome Forums General PowerShell Q&A Compress-Archive with hidden items

Viewing 2 reply threads
  • Author
    Posts
    • #243956
      Participant
      Topics: 8
      Replies: 558
      Points: 2,136
      Helping Hand
      Rank: Community Hero

      I’m trying to zip a folder that contains some hidden files and folders. I noticed that Compress-Archive does not grab these so I thought I’d simply pass all the items.

      This is met with a nasty error. It looks like Get-Item is failing to query the hidden files.

      Testing confirmed Get-Item would also need the -Force parameter to query it. Is there a work around I’m not finding? Or should I just use 7zip or similar? I do not want to change the attributes just to zip them. If I zip them in Windows Explorer it zips them all just fine.
      I appreciate any input.

    • #244007
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      I could reproduce the error. You could workaround with using a Foreach-Object loop and the parameter -Update but that would produce another weird error. I’d probably rather use 7zip instead. 😉

    • #244661
      Participant
      Topics: 11
      Replies: 127
      Points: 763
      Helping Hand
      Rank: Major Contributor

      This works using .NET but the hidden attribute isn’t preserved (if that doesn’t matter once zipped):

      There isn’t an overload for overwriting existing files but there are plenty of ways to handle that beforehand.

      https://docs.microsoft.com/en-us/dotnet/api/system.io.compression.zipfile.createfromdirectory?view=netcore-3.1

      • This reply was modified 1 month, 3 weeks ago by Aaron Hardy. Reason: open link in new tab
Viewing 2 reply threads
  • You must be logged in to reply to this topic.