Sunday 27 May 2012

make zip file though cmd/ batch


------ New Stylish Way ----------------------------



make a file "zip.vbs"'



'script made by Gaurav D. Sharma
' this cmd / batch file use for make zip...
'CScript  zip.vbs "sourcepath" "targetPath" timeInSeconds
'CScript  zip.vbs  "C:\test1" "H:\mytest1\backup\fileName" 10





'Get command-line arguments.
Set objArgs = WScript.Arguments
InputFolder = objArgs(0)
timeStamp = Replace( FormatDateTime(Now,3) , ":" ,"_" )
dateStamp  =  FormatDateTime(Now,1) &"_"& timeStamp 
ZipFile = objArgs(1) &"__"&Replace( dateStamp  , " " ,"" ) & ".zip"


'Create empty ZIP file.
CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)


Set objShell = CreateObject("Shell.Application")


Set source = objShell.NameSpace(InputFolder).Items


objShell.NameSpace(ZipFile).CopyHere(source)




Wscript.Echo "-"
Wscript.Echo "* Script by Gaurav D. Sharma"
Wscript.Echo "----------------------------"
Wscript.Echo ""
Wscript.Echo "script is working, please wait . . ."
Wscript.Echo ""


'Required!
wScript.Sleep objArgs(2)*1000



make a batch file "makeZip.bat"



:: script made by Gaurav D. Sharma


echo off
color a
cls


:: CScript  zip.vbs "sourcePath" "targetPath" timeInSeconds


CScript  zip.vbs  "C:\wamp\www\openNGO" "H:\openNGO\backup\openNGO" 10


::pause







--- old stylish  way -------------------------------------------------------

make a file "zip.vbs"

'Get command-line arguments.

Set objArgs = WScript.Arguments
InputFolder = objArgs(0)
timeStamp = Replace( FormatDateTime(Now,3) , ":" ,"_" )
dateStamp  =  FormatDateTime(Now,1) &"_"& timeStamp 
ZipFile = objArgs(1) &"__"&Replace( dateStamp  , " " ,"" ) & ".zip"


'Create empty ZIP file.
CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)


Set objShell = CreateObject("Shell.Application")


Set source = objShell.NameSpace(InputFolder).Items


objShell.NameSpace(ZipFile).CopyHere(source)


'Required!
wScript.Sleep 2000




make a batch file "makeZip.bat"



echo off
color a
cls
CScript  zip.vbs  "C:\sourceFolder" "c:\targetFolder"
pause

---- Normal standard way ---------------------------------------------


make a file "zip.vbs"

'Get command-line arguments.
Set objArgs = WScript.Arguments
InputFolder = objArgs(0)
ZipFile = objArgs(1)


'Create empty ZIP file.
CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)


Set objShell = CreateObject("Shell.Application")


Set source = objShell.NameSpace(InputFolder).Items


objShell.NameSpace(ZipFile).CopyHere(source)


'Required!
wScript.Sleep 2000


make a batch file "makeZip.bat"


CScript  zip.vbs  C:\test3  C:\someArchive.zip

No comments:

Post a Comment