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
361 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
 
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
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.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to roll back kernel via script 4 62
Remote install of MSI file 4 41
Launch Process with NOT as Administrator 15 79
how to pick only current date files from a ftp 14 53
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Utilizing an array to gracefully append to a list of EmailAddresses
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.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

27 Experts available now in Live!

Get 1:1 Help Now