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
353 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
EXCHANGE 2007, SCRIPTS 67 69
count11 challenge 6 47
Launch Process with NOT as Administrator 15 67
Need to learn promise API 2 28
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 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

21 Experts available now in Live!

Get 1:1 Help Now