Is there a way to copy files from a folder to a zip file using Inno Setup?
My installer script creates a Temp Folder and I would like to move the content (mix of files and folders) to an existing zip file. I don't need compression or anything fancy...
I thought, and I know this is dumb, that this would be possible using FileCopy because (as far as I know) MS Windows treats copying to a zip folder in a similar way as copying to a directory.
[Update 1] Ok - found a vbs script that does what I want, after some minor changes:
Dim fso, winShell, h, MyTarget, MySource
MySource = Wscript.Arguments.Item(0)
MyTarget = Wscript.Arguments.Item(1)
Set fso = CreateObject("Scripting.FileSystemObject")
Set winShell = createObject("shell.application")
Set h = fso.getFile(MyTarget)
'Wscript.Echo "Adding " & MySource & " to " & MyTarget
winShell.NameSpace(MyTarget).CopyHere winShell.NameSpace(MySource).Items
do
wscript.sleep 500
max = h.size
loop while h.size > max
Set winShell = Nothing
Set fso = Nothing
And ran it from command line like this:
Cmd (run as admin)
C:MyScriptLocationWScript ZipScript.vbs "MySourceDirPath" "MyDestDirPathMyZipFile.zip"
So now I need to get it to run from Inno :-)
[Update 2] Ok - got it running from Inno, revised the script:
Dim objFSO, objTxt, winShell, h
Dim myFolder, myZipFile
Const ForWriting = 2
myFolder = Wscript.Arguments.Item(0)
myZipFile = Wscript.Arguments.Item(1)
Wscript.Echo "Planning to add Source: " & myFolder & " to Target: " & myZipFile
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Wscript.Echo "Creating myZipFile" & myZipFile
' Create an empty ZIP file
Set objTxt = objFSO.OpenTextFile( myZipFile, ForWriting, True )
objTxt.Write "PK" & Chr(5) & Chr(6) & String( 18, Chr(0) )
objTxt.Close
Set objTxt = Nothing
Set winShell = createObject("shell.application")
Set h = objFSO.getFile(myZipFile)
Wscript.Echo "Started Copy Process" & myZipFile
winShell.NameSpace(myZipFile).CopyHere winShell.NameSpace(myFolder).Items, true
do
wscript.sleep 1000
max = h.size
loop while h.size > max
Set winShell = Nothing
Set objFSO = Nothing
I am running from Inno using:
[Run]
Filename: "PackItUp.vbs"; Parameters: """{code:GetDataDir_S|0}Temp"" ""{code:GetDataDir_S|0}myZip.zip"""; WorkingDir: "{code:GetDataDir_S|0}"; Flags: shellexec runascurrentuser
Which seems to work, but I am unsure if this is a good solution.
See Question&Answers more detail:
os