# Copy Files from ZIP archives

**URL:** <https://forums.powershell.org/t/copy-files-from-zip-archives/4071>\
**Category:** PowerShell Help\
**Created:** [April 20, 2015, 10:53am UTC](https://forums.powershell.org/t/copy-files-from-zip-archives/4071 "2015-04-20T10:53:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bernie-carolan](https://avatars.discourse-cdn.com/v4/letter/b/aeb1de/32.png) [@bernie-carolan](https://forums.powershell.org/u/bernie-carolan)\
**Post date:** [April 20, 2015, 10:53am UTC](https://forums.powershell.org/t/copy-files-from-zip-archives/4071/1 "2015-04-20T10:53:01Z")

</div>

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

The input file is in the format:

C:\Store\firstfile.txt  
C:\Store\secondfile.txt  
etc.

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

C:\Store\Logs\mylog.zip\filetobecopied.txt

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

C:\Store\Logs\mylog.zip\Reports\filetobecopied.txt.

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 = $ObjSourceFile.name
$SourceDirectory = $objSourceFile.DirectoryName

```

Is there a way of achieving this?

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [April 20, 2015, 10:25pm UTC](https://forums.powershell.org/t/copy-files-from-zip-archives/4071/2 "2015-04-20T22:25:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [April 21, 2015, 12:57am UTC](https://forums.powershell.org/t/copy-files-from-zip-archives/4071/3 "2015-04-21T00:57:57Z")

</div>

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

```
$shellApp = New-Object -ComObject Shell.Application
$destination = 'F:\' 
$fileToCopy = 'F:\__Temp\robots.zip\robots.txt'
$shellApp.NameSpace($destination).copyhere($fileToCopy)
```

---

<div class="post-metadata">

**Author:** ![bernie-carolan](https://avatars.discourse-cdn.com/v4/letter/b/aeb1de/32.png) [@bernie-carolan](https://forums.powershell.org/u/bernie-carolan)\
**Post date:** [April 21, 2015, 1:34pm UTC](https://forums.powershell.org/t/copy-files-from-zip-archives/4071/4 "2015-04-21T13:34:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:45pm UTC](https://forums.powershell.org/t/copy-files-from-zip-archives/4071/5 "2024-05-16T20:45:27Z")

</div>


