1

I am quiet new on this environment, my question is that, I am using 7z for compressing files, but could you help me about how to do it with the .zip extension? Due to I am a dummy about batch, I just created environmental variables and I can copy move files from one to other. But getting a file with the zip extension is hard for me. I have been seraching it for along time. And also I have another quesion about this batch, I can run it on my own computer with Windows 7 OS, however I cannot do the same with my customer's computer where I want to run this script on Microsoft SQL Server 2012, by the way the master folder's name has space and I get error with it too.

echo off

if not exist "C:\Pack"  mkdir %genericPath%\Pack
if not exist "C:\ProAgent"  mkdir  %genericPath%\Pack\ProAgent
if not exist "C:\ProAgent1230" mkdir %genericPath%\Pack\ProAgent1230

xcopy /b /v /y /s  %genericPath%\Filter-Inventory\filter.ini %genericPath%\Pack\ProAgent
xcopy /b /v /y /s  %genericPath%\Filter-Inventory\pvinvent.ini %genericPath%\Pack\ProAgent
xcopy /b /v /y /s  %genericPath%\Registry\updateProAgent.reg %genericPath%\Pack\ProAgent1230
xcopy /b /v /y /s  %genericPath%\Files\$update$.bat %genericPath%\Pack\ProAgent1230
xcopy /b /v /y /s  %genericPath%\Files\runscript.vbs %genericPath%\Pack\ProAgent1230
xcopy /b /v /y /s  %genericPath%\Files\runupdate.bat %genericPath%\Pack\ProAgent1230
xcopy /b /v /y /s  %genericPath%\Files\updateAgent.cmd %genericPath%\Pack\ProAgent1230

:Archieve
set archievePatch= %genericPath%\Pack

7z.exe a %genericPath%\Pack "%archievePatch%" 

rmdir /s /q "%genericPath%\Pack"

PATH %genericPath%\FF

exit
Vojtech Ruzicka
  • 16,384
  • 15
  • 63
  • 66
  • since when has sql server ever been able to run batch files? – Marc B May 31 '16 at 19:45
  • Can you explain what you want to achieve with simple example? – E.Meir May 31 '16 at 19:48
  • I mean we have a monitoring software and it distributes files. But i want to distribute the pack with zip. I am using rules and jobs to do it. Creating a job to run this batch and zip files, After that one another job to distrbute. – Gokmen Kutuk May 31 '16 at 19:48
  • I want to zip the file /Pack/ but with the .zip extension not 7zip or rar. – Gokmen Kutuk May 31 '16 at 19:50
  • i believe this one will help: http://stackoverflow.com/questions/21704041/creating-batch-script-to-unzip-a-file-without-additional-zip-tools – E.Meir May 31 '16 at 19:52
  • but this is for unzip, i need one to zip lol :) – Gokmen Kutuk May 31 '16 at 19:59
  • the first answer is with bat file: http://superuser.com/questions/110991/can-you-zip-a-file-from-the-command-prompt-using-only-windows-built-in-capabili – E.Meir May 31 '16 at 20:39

2 Answers2

0

You need to specify the output type:

7z.exe a -tzip %genericPath%\Pack "%archievePatch%"\

Alternatively:

7z.exe a %genericPath%\Pack.zip "%archievePatch%"\

(Note: the backslash on the source is necessary since it signifies the folder)

Checkout these sites:

Examples of 7zip command: http://www.dotnetperls.com/7-zip-examples

Zipping folders: http://www.wikihow.com/Use-7Zip-to-Create-Multiple-Compressed-Folders-in-One-Go

Harvey Pham
  • 623
  • 4
  • 17
  • hey, but it just changes the extension? Because when i get into the zip file, i do not see there a folder with name Pack :) – Gokmen Kutuk Jun 01 '16 at 05:52
  • I overlooked another issue in your command. You need to specified that your source is a folder, not file by adding a backslash (\) at the end. I updated my post to reflect this. – Harvey Pham Jun 01 '16 at 15:38
0

thank you for your help. I've configured the script and than now i can get Pack.zip with the script given below. However i cannot do the same on my customer's computer. When i define a specific path on environmental variables, it does not work. The destination folder is in a master folder with the name of Win Nix and when i am trying to create this zip file, it just creates me a file with the name of Nix and no zip, no copied files included. How can i solve this?

Thanks

echo off

    if not exist "C:\Pack" mkdir %genericPath%\Pack
    if not exist "C:\ProAgent" mkdir %genericPath%\Pack\ProAgent
    if not exist "C:\ProAgent1230" mkdir %genericPath%\Pack\ProAgent1230

    xcopy /b /v /y /s %genericPath%\Filter-Inventory\filter.ini %genericPath%\Pack\ProAgent
    xcopy /b /v /y /s %genericPath%\Filter-Inventory\pvinvent.ini %genericPath%\Pack\ProAgent
    xcopy /b /v /y /s %genericPath%\Registry\updateProAgent.reg %genericPath%\Pack\ProAgent1230
    xcopy /b /v /y /s %genericPath%\Files\$update$.bat %genericPath%\Pack\ProAgent1230
    xcopy /b /v /y /s %genericPath%\Files\runscript.vbs %genericPath%\Pack\ProAgent1230
    xcopy /b /v /y /s %genericPath%\Files\runupdate.bat %genericPath%\Pack\ProAgent1230
    xcopy /b /v /y /s %genericPath%\Files\updateAgent.cmd %genericPath%\Pack\ProAgent1230


    set archievePatch= %genericPath%\Pack


    echo Set objArgs = WScript.Arguments > _zipIt.vbs
    echo InputFolder = objArgs(0) >> _zipIt.vbs
    echo ZipFile = objArgs(1) >> _zipIt.vbs
    echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> _zipIt.vbs
    echo Set objShell = CreateObject("Shell.Application") >> _zipIt.vbs
    echo Set source = objShell.NameSpace(InputFolder).Items >> _zipIt.vbs
    echo objShell.NameSpace(ZipFile).CopyHere(source) >> _zipIt.vbs
    echo wScript.Sleep 2000 >> _zipIt.vbs

    CScript  _zipIt.vbs  %archievePatch%  %genericPath%\Pack.zip
    rmdir /s /q "%genericPath%\Pack"
    exit