Solved

I need help with a script a batch file that when run zip's all folders and files

Posted on 2011-09-23
17
369 Views
Last Modified: 2012-05-12
I need help with a script a batch file that when run zip's all folders and files with a folder and names it with current date
Can anyone help with this
Winzip extractable zip
0
Comment
Question by:bsharath
  • 8
  • 6
  • 2
  • +1
17 Comments
 
LVL 3

Expert Comment

by:chandrasekar1
ID: 36586034
checkout the below link, it may help you

http://sgwindowsgroup.org/forums/t/2293.aspx   (remove the delete logic from the script)
http://apdubey.blogspot.com/2008/09/backupcompress-and-rename-folder-with.html
0
 
LVL 1

Expert Comment

by:lyncks
ID: 36586159
hello,
tested on solaris

#!/usr/bin/sh
WorkPath="/path"
archive=`date "+%Y%m%d"`
mkdir ${WorkPath}/${archive}
cp -r ${WorkPath}/*xxx* ${WorkPath}/${archive}
zip ${WorkPath}/${archive} -r ${WorkPath}/${archive}

hope this helps
0
 
LVL 11

Author Comment

by:bsharath
ID: 36598114
Is this batch code?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 1

Expert Comment

by:lyncks
ID: 36599319
hello,
I don't know what is a batch code. it's a script I tested on solaris.
0
 
LVL 11

Author Comment

by:bsharath
ID: 36679598
What script is this how should i run it.

.bat .vbs?
0
 
LVL 11

Author Comment

by:bsharath
ID: 36679605
How should i mention the folder from and To?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36707858
Which command line utility do you want to use for the zipping?  I've used 7zip and UltimateZip before, which you'll find examples here on EE.  There is also this one that should work without either of those:
http://www.experts-exchange.com/Programming/Languages/Scripting/Q_26780535.html

Regards,

Rob.
0
 
LVL 11

Author Comment

by:bsharath
ID: 36707914
Thanks
Rob can i have which uses none or winzip and zips the folders into date
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36708584
OK, the one that doesn't use a zip program didn't work on Windows 7, so here's the one that uses Winzip, although I haven't tested it because I don't have winzip.

Regards,

Rob.
strDate = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)

strFolderToZip = "C:\Temp\Scripts"
strZipFileToCreate = "C:\Temp\Scripts_" & strDate & ".zip"
strWinzip = "C:\Program Files\WinZip\Winzip32.exe"

Set objFSO = CreateObject("Scripting.FileSystemObject")
strWinZip objFSO.GetFile(strWinZip).ShortPath
strCommand = strWinzip & " -min -a -r """ & strZipFileToCreat & """ """ & strFolderToZip & """"
objShell.Run strCommand, 1, True

MsgBox "Done"

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 36901953
Rob i get this error


---------------------------
Windows Script Host
---------------------------
Script:      F:\Zip.vbs
Line:      6
Char:      1
Error:      Type mismatch: 'strWinzip'
Code:      800A000D
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36902038
Sorry, typo.

Change this:
strWinZip objFSO.GetFile(strWinZip).ShortPath

to this
strWinZip = objFSO.GetFile(strWinZip).ShortPath

Rob.
0
 
LVL 11

Author Comment

by:bsharath
ID: 36903307
I get this

---------------------------
Windows Script Host
---------------------------
Script:      F:\Zip.vbs
Line:      8
Char:      1
Error:      Object required: 'objShell'
Code:      800A01A8
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36906637
Sorry...I hadn't tested it.

Rob.
strDate = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)

strFolderToZip = "C:\Temp\Scripts"
strZipFileToCreate = "C:\Temp\Scripts_" & strDate & ".zip"
strWinzip = "C:\Program Files\WinZip\Winzip32.exe"

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strWinZip = objFSO.GetFile(strWinZip).ShortPath
strCommand = strWinzip & " -min -a -r """ & strZipFileToCreate & """ """ & strFolderToZip & """"
objShell.Run strCommand, 1, True

MsgBox "Done"

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 36907505
Rob i get this


---------------------------
WinZip
---------------------------
Error: Could not create output file (C:\Test\subfolder_20111004074642.zip).
---------------------------
OK   Help  
---------------------------



I have the vbs and a folder called test and a sub folder called "Subfolder"
Inside test i have a text file

When run i get the message above
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36907689
I think you need to make sure you don't hav anything accessing what you want to zip.

If you're on Windows Vista or 7, try running a command prompt as administrator, then running
cscript d:\zip.vbs

just to see whether that works.  It worked for me when I tested it with Winzip 9.

Rob.
0
 
LVL 11

Author Comment

by:bsharath
ID: 36929098
Rob still get same message. Any other ways
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 36977742
Well if you can use 7-Zip (which is free, and you might get away with just using the EXE), I just tested this code.

If you want, you can just install 7-Zip on one computer, then copy the 7z.exe and 7z.dll files to a network share, and then access the 7z.exe from that share.

Regards,

Rob.
strDate = Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)

strFolderToZip = "C:\Temp\Scripts"
strZipFileToCreate = "C:\Temp\Scripts_" & strDate & ".zip"
str7Zip = "C:\Program Files\7-Zip\7z.exe"

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
str7Zip = objFSO.GetFile(str7Zip).ShortPath
strCommand = str7Zip & " a -r """ & strZipFileToCreate & """ """ & strFolderToZip & """"
objShell.Run strCommand, 1, True

MsgBox "Done"

Open in new window

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

832 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