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

  • Question

  • Hi:

    Here are my folder structure

    rootFolder-----

                         | sub1

                         | sub2

                         | sub3-----

                                         | ssub1

    Here are my code

    $DirToCompress="d:\rootFolder"
    $ZipFileResult="d:\zipFile.zip"
    $DirToExclude=@("ssub1")

    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 !!


    my407sw

    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" ?

    my407sw

    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