remove files from zipped folders

Welcome Forums General PowerShell Q&A remove files from zipped folders

This topic contains 6 replies, has 3 voices, and was last updated by

2 years ago.

  • Author
  • #63748

    Points: -19
    Rank: Member

    Hi all,

    well i have suffered for many days to get this code for my case but unfortunately i failed:(

    i want to go on target path folder which contains about 500 zipped files then open each on of them and delete one folder and another single file

    as shown on below link

    open Zip filder —> go on (xl) folder —> delete (queryTables) and (connections.xml)

    any help or hint please

    Thanks in advance

  • #63755

    Points: 0
    Rank: Member

    Do you have code that works up to a point?

    If you are trying to work with zip files powershell 5 does have some commands to help. see

  • #63763

    Points: 17
    Rank: Member

    This will delete the folder and file from your zips.

    $zip = Get-ChildItem \\path\to\zips -Filter *.zip
    add-type -AssemblyName 'System.IO.Compression.filesystem'
    # Change zip file
    foreach ($z in $zip){
        Write-Verbose "Updating $($" -Verbose
        $tempz = [io.compression.zipfile]::Open($z.FullName,'Update')
        $entry = $tempz.Entries | Where-Object {
        $_.fullname -match 'queryTables|connections.xml'}
        foreach ($e in $entry){$e.Delete()}
    • #63803

      Points: -19
      Rank: Member


      well at the first thanks for your reply and code

      but when i used it i found that error msg below

      View post on

      any idea why??

      and i already have "System.IO.Compression.FileSystem.dll" on my ".NETFramework\v4.5" folder

  • #63850

    Points: 17
    Rank: Member



    Check PSVersion and CLRVersion (.NET Version)
    What versions of PowerShell and .NET are installed? I tested it with PS:3.0 / CLR:4.0.30319.42000.
    Update .NET and at least to PS 3.0

    • #63889

      Points: -19
      Rank: Member

      oh works perfect now, really i don't find enough words to thank you

      one more request please and anyway don't push your self to answer if you are busy

      i'm looking now to add (.zip) to all files at target path folder to be zipped manually and individually

      then i want to reverse this process with another code, delete (.zip) to all individually too

      for ex,

      Test.xls —> —> Test.xls

      and to be applied on many files at target path folder

      can it be

      Thanks in advance


  • #63892

    Points: -19
    Rank: Member

    well i think i got it finally 😀 😀

    Dir *.xls | rename-item -newname { [io.path]::ChangeExtension($, "") }

    Thanks a lot for your care

The topic ‘remove files from zipped folders’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort