Copy Files from ZIP archives

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Bernie Carolan Bernie Carolan 2 years, 3 months ago.

  • Author
  • #24484
    Profile photo of Bernie Carolan
    Bernie Carolan

    I have a script to copy files from one location to another based on an input file.

    The input file is in the format:


    This all works fine, but the input file also contains references to a file within a zip file in the format:


    Where filetobecopied.txt is inside The zip file may also contain a folder structure, e.g


    I've tried the following so far,, but no success (powershell v3)

    get-content $sourceFile | foreach-object {

    $FileToCopy = $_
    if ($FileToCopy.Contains(".zip")) {

    $FileToCopy = $FileToCopy.Substring(0, $s.IndexOf('.zip')) + '.zip'
    $ObjSourceFile = get-item $FileToCopy

    $SourceFileName = $
    $SourceDirectory = $objSourceFile.DirectoryName

    Is there a way of achieving this?

  • #24491
    Profile photo of Don Jones
    Don Jones

    You can't read a file directly from a ZIP; you would need to first expand the ZIP.

  • #24514
    Profile photo of Matt Bloomfield
    Matt Bloomfield

    You can do this with a Shell.Application COM object.
    My test file contains a file called robots.txt

    $shellApp = New-Object -ComObject Shell.Application
    $destination = 'F:\' 
    $fileToCopy = 'F:\__Temp\\robots.txt'
  • #24531
    Profile photo of Bernie Carolan
    Bernie Carolan

    Thanks Matt, that was exactly what I was looking for.

You must be logged in to reply to this topic.