How to use PowerShell compress folder but must not include some sub folder ? RRS feed

  • Question

  • Hi:

    Here are my folder structure


                         | sub1

                         | sub2

                         | sub3-----

                                         | ssub1

    Here are my code


    Get-ChildItem $DirToCompress -Directory | 
               where { $_.Name -notin $DirToExclude} |
               Compress-Archive -DestinationPath $ZipFileResult -Update -CompressionLevel Fastest

    When I open the zip file, it still include subfolder "ssub1" , how can I change my code let zip  file not include "ssub1" ?

    thanks !!


    Wednesday, May 17, 2017 11:55 AM

All replies

  • You cannot skip a subfolder if you add the parent.  "Compress" will always compress the whole hierarchy.  Us a third party compression program for greater ability to customize the zip.


    Wednesday, May 17, 2017 3:01 PM
  • Can I skip some file like *.wmv *.mp4  in "ssub1" ?


    Wednesday, May 17, 2017 3:18 PM
  • Get-ChildItem c:\folder\* -exclude *.mp4 |
         Compress-Archive -DestinationPath c:\temp\arc.zip


    • Proposed as answer by Hello_2018 Saturday, May 27, 2017 6:07 AM
    Wednesday, May 17, 2017 3:24 PM