Solved

zip sub-folders in folder using script

Posted on 2014-01-22
4
1,016 Views
Last Modified: 2014-01-23
I'd like a script to zip each sub-folder in a folder.
Then delete the folder.

My folder contains 1589 sub-folders, and i'd like each folder zipped and then the original folder deleted.

I'd be grateful for any help
Regards
0
Comment
Question by:antonioking
  • 2
  • 2
4 Comments
 

Author Comment

by:antonioking
ID: 39799941
I've managed to create the script myself...
Dim strFolder, subfolder, folder, strMessage

strFolder = "<FOLDERPATH>"
Set folder = CreateObject("Scripting.FileSystemObject").GetFolder(strFolder).SubFolders

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")

For Each subfolder in folder
	oshell.run """C:\Program Files (x86)\7-Zip\7z.exe"" a -r " & strFolder & "\" & subfolder.name & ".zip " & strFolder & "\" & subfolder.name & "\*"
Next

Open in new window

0
 
LVL 52

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39799984
Here's a small BAT approach if you have 7zip (or download it).

@echo off
setlocal EnableDelayedExpansion

set z=c:\program files\7-zip\7z.exe
set BaseDir=c:\base
set DestDir=d:\dest

for /D %%D in ("%BaseDir%\*.*") do (
  "%z%" a -tzip "%DestDir%\%%~nD.zip" "%%~D\*.*"
  rd /q /y "%%~D"
)

Open in new window

~bp
0
 

Author Closing Comment

by:antonioking
ID: 39802432
Thanks Bill
Your script is better as it waits for each folder to be zipped before moving to the next one.
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 39805038
Welcome, thanks for the feedback.

~bp
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now