?
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
Medium Priority
?
398 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
[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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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 …
Suggested Courses

770 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