AnsweredAssumed Answered

Zip Project and get log file

Question asked by gw@byk on Jul 2, 2020

Hi everyone,

 

I want to zip my whole project, using 7zip; Zipping works fine, but I want to get a log file from the 7zip-console-application so I can see, whether everything was OK. This is my vbs-code: 

Option Explicit     

Call ZipMyProject

Sub ZipMyProject ()
     
     Dim WSHSHell                : Set      WSHSHell               = CreateObject("WScript.Shell")
     Dim dxdApp                    : Set      dxdApp                     = Application
     Dim FSO                     : set      FSO                     = CreateObject("Scripting.FileSystemObject")
     Dim dxdView                 : Set      dxdView                = dxdApp.ActiveView                                        ' Get the active document
     Dim dxddoc
     Dim sdd_home                :           sdd_home                = Scripting.GetEnvVariable("SDD_HOME")     'System-Env-Variable
     Dim prj                         : set      prj                     = dxdApp.GetProjectData                         'Get the active Project
     Dim prjPath                    :           prjPath                = prj.GetProjectPath                                    'Dateipfad, in dem das Project liegt.
     Dim prjFilePath               :           prjFilePath           = prj.GetProjectFilePath                               'Direkter Link zum PRJ
     Dim ArchPath               :           ArchPath               = FSO.GetParentFolderName(prjPath)
     
     Dim command     
     Dim Line
     Dim result
     
     Dim ZipExePath                :           ZipExePath                = "C:\Program Files\7-Zip"
     
     Dim len1                    :           len1                     = len(prjFilePath)     ' .prj wird mitgezählt
     Dim len2                    :          len2                     = len(prjPath)
     Dim len3                    :          len3                     = Len1 - len2 -1 ' \ wird mitgezählt
     Dim PCSysTime               :          PCSysTime               = Year(Now) & "-" & LPad(Month(Date), "0", 2) & "-" & LPad(Day(Date), "0", 2) ' jjj-mm-dd
     Dim RightPart               :           RightPart                = right (prjFilePath, Len3)
     Dim LeftPart               :          LeftPart                = left (RightPart, (Len3-4))
     Dim ArchFilePath          :          ArchFilePath           = ArchPath & "\" & PCSysTime & "_" & LeftPart & ".zip" ' Ort, in den die zip-Datei erzeugt wird; Dateiname mit erweiterung (xxx.zip)
     Dim LogfileFilePath          :          LogfileFilePath      = ArchPath & "\" & "ziplog.txt" 'PCSysTime & "_" & "log.txt"
     
     
     'command=  """" & ZipExePath & "\7z.exe"" a  """ & ArchFilePath & """ """ & prjPath & """" ', 0, True  'this line will zip my project folder (working)
     
     command = """" & ZipExePath & "\7z.exe"" a  """ & ArchFilePath & """ """ & prjPath & """"  & " >" & chr(34) & LogfileFilePath & chr(34)
     
     WSHSHell.Run command, 0, True


End Sub


Function LPad (str, pad, length)
    LPad = String(length - Len(str), pad) & str
End Function


Function WaitXSec(WaitTime)
     Dim dteWait
     
     dteWait = DateAdd("s", WaitTime, Now())
     Do Until (Now() > dteWait)
     Loop
end Function

Line 34 will work just fine and I get the project compressed. Line 36 will compress the project too, but there will be no log file generated. 

I tried compressing the project using powershell window directly, using the code below; this worked with a log file being generated:

$ZipExePath="C:\Program Files\7-Zip\7z.exe"
$ArchFilePath="N:\Sample Project ParentFolder\Sample Project Archive.zip"
$prjPath="N:\Sample Project ParentFolder\Sample Project"
$LogfileFilePath="N:\Sample Project ParentFolder\ziplog.txt"
& $ZipExePath a  $ArchFilePath $prjPath >$LogfileFilePath

 

 

 

I appreciate any hint, 

kind regards,

Georg

Outcomes