Solved

zip sub-folders in folder using script

Posted on 2014-01-22
4
1,019 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 53

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 53

Expert Comment

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

~bp
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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