windows extract files

#1
Hi,
I don't know if it's a right place to ask this question ...
I have a shared folder of zip files, I want to unzip them and put the new folder(same name as zip folder with files extracted in it ) in new location each time there's a new zip in shared folder, is there a tool how can do it ? or I need to develop a batch ?
thank you
 


Neemobeer

Windows Forum Team
Staff member
#2
I don't know of any application that will monitor and process zip archives like that, but you could create a powershell script and set it up as a scheduled task to check for newly added zips and process them.
 


BIGBEARJEDI

Fantastic Member
Premium Supporter
#3
Hi and welcome to the Forum :up:

Take a look at this link here: How to Use 7Zip to Create Multiple Compressed Folders in One Go

The article tells you how to do this to create both unzipped and zipped files into your target directory using the free 7zip utility. I've been using 7zip for years, and it's a safe and easy to use program.:thumbs_up: I'm not sure if you're intended for the unzip event to run every time there is a new zip added to the shared source folder automatically or not. But, this batch file will do most of the work for you. You can probably use the Windows scheduler or a 3rd party event scheduler app to read the shared folder, and create a trigger within the scheduler app to sense any changes (new file additions or deletions) and then have the scheduler app call the 7zip batch file shown in the article (only 1 line of code). The 7zip batch file will do the rest. I've seen something similar in XP and Vista done with the built-in Windows scheduler app. You can probably google it, and it's pretty easy to use. Most of the work would be creating the 7zip batch file to unzip to multiple target directories sequentially--and this batch file already does that for you!

Give it a try,:)
<<<BIGBEARJEDI>>>
 


BIGBEARJEDI

Fantastic Member
Premium Supporter
#4
@neemo: I think we're on the same page here! The link to the 7zip batch file should help her get started.
BBJ
 


Neemobeer

Windows Forum Team
Staff member
#5
Yeah a script with the 7zip CLI would work too. I tend to recommend powershell because you can accomplish the task without any extra software.
 


#6
thank you for the help,yes I would like to unzip added zip files automatically, I will try it,
meanwhile I found a batch :

@echo off
setlocal
cd /d %~dp0
Call :UnZipFile "C:\path\unzipped\" "c:\path\zipped\batch.zip"
exit /b

:UnZipFile <ExtractTo> <newzipfile>
set vbs="%temp%\_.vbs"
if exist %vbs% del /f /q %vbs%
>%vbs% echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%vbs% echo If NOT fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Application")
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%

but it works for 1 zip and not all,

this code didn't work for me :
@echo off
setlocal
cd /d %~dp0
for %%a in (*.zip) do (
Call :UnZipFile "C:\Temp\%%~na\" "c:\path\to\%%~nxa"
)
exit /b
any ideas ?
 


Neemobeer

Windows Forum Team
Staff member
#7
Batch files are so ugly and difficult to follow lol. I wrote this very simply powershell script that will work. You only need to change the unzipDirectory and zipDirectory paths

Code:
$unzipDirectory = "C:\Users\username\Desktop\Unzip"
$zipDirectory = "C:\Users\username\Desktop\Zip"

$zipFiles = Get-ChildItem -Path $zipDirectory -Filter "*.zip"

Foreach($zipFile in $zipFiles)
{
    $unzipPath = "$($unzipDirectory)\$($zipFile.Name.Split(".")[0])"
    If (-not (Test-Path $unzipPath))
    {
        New-Item -Path $unzipPath -ItemType Directory

        $shellObject = New-Object -ComObject shell.application
        $zipArchive = $shellObject.NameSpace($zipFile.FullName)

        foreach($file in $zipArchive.items())
        {
            $shellObject.NameSpace($unzipPath).copyhere($file)
        }
    }
}
 


#8
I found this code to watch the folder, but I am a begginer in powershell, so I don't know how it will work automatically, and how to add your code to this code :

$folder = 'c:\....'
$filter = '*.*'
$fsw = New-Object IO.FileSystemWatcher $folder, $filter
$fsw.IncludeSubdirectories = $true
$fsw.NotifyFilter = [IO.NotifyFilters]'DirectoryName' # just notify directory name events
$onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
#how can I call the unzip script ? }
 


Last edited:

Neemobeer

Windows Forum Team
Staff member
#9
There is no trigger to detect a file added to a directory. You can use "On a schedule" Run it Daily and under Advanced Settings select "Repeat task every" can go as low as 5 minutes.

Under general just have the task run as SYSTEM and run whether a use is logged in or not.
The other option to having it run all the time is you could have it run once and add a loop into the powershell code so it simply runs all the time on a loop.

Wrap the following code around the above code.

While($true)
{
[code from above]

Start-Sleep -Seconds #ofseconds to sleep

}
 


This website is not affiliated, owned, or endorsed by Microsoft Corporation. It is a member of the Microsoft Partner Program.