Solved

zip sub-folders in folder using script

Posted on 2014-01-22
4
1,025 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 54

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 54

Expert Comment

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

~bp
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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