Looping and Zipping of files
Posted: 29 Mar 2011 23:11
Hi All,
I am new to Dos Batch. My problem now is that I need to loop through a directory with many subfolders. I need to zip those subfolders (using 7zip) and place the zipped subfolders into another directory.
Before zipping
My main root is C:\Users\ayaka\Desktop\ZipTask\TestingDirectory
Sample Folders:
C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\April2001\temp123\temp123.html
C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\April2001\temp234\temp234.html
C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\May2001\temp345\temp345.html
C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\May2001\temp456\temp456.html
After zipping
C:\Users\ayaka\Desktop\ZipTask\TestDir
The folders should be zip according to the month and year. So, there should be 2 zipped folders, mainly April2001 and May2001 in C:\Users\ayaka\Desktop\ZipTask\TestDir
I had done abit of coding, but it doesn't really work.
Here's the code:
Can anyone help me? Thanks.
I am new to Dos Batch. My problem now is that I need to loop through a directory with many subfolders. I need to zip those subfolders (using 7zip) and place the zipped subfolders into another directory.
Before zipping
My main root is C:\Users\ayaka\Desktop\ZipTask\TestingDirectory
Sample Folders:
C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\April2001\temp123\temp123.html
C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\April2001\temp234\temp234.html
C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\May2001\temp345\temp345.html
C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\May2001\temp456\temp456.html
After zipping
C:\Users\ayaka\Desktop\ZipTask\TestDir
The folders should be zip according to the month and year. So, there should be 2 zipped folders, mainly April2001 and May2001 in C:\Users\ayaka\Desktop\ZipTask\TestDir
I had done abit of coding, but it doesn't really work.
Here's the code:
Code: Select all
@ECHO off
FOR /R C:\Users\ayaka\Desktop\ZipTask\TestingDirectory\ %%G IN (*) DO (
for /f "tokens=1-7 delims=\ " %%i in ("%%G") do (
Set folder=%%o
Set path=%%i\%%j\%%k\%%l\%%m\%%n\%%o
cd C:\Users\ayaka\Desktop\ZipTask\7za920
7za.exe a -t7z %path%\%folder%.7z C:\Users\ayaka\Desktop\ZipTask\TestDir
)
)
@ECHO on
Can anyone help me? Thanks.