Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
?
410 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

618 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