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:\MyScriptLocation\WScript ZipScript.vbs "MySourceDirPath" "MyDestDirPath\MyZipFile.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.
This is a nice feature that I've never heard about. The
Folder
objectCopyHere
method can append files or folders to existing archive files. With late binding you can write as little as this (even the VB script in your question was overcomplicated since this method accepts also file name passed as string):The
Archive
parameter in the above function must be the name of an existing archive file (I've tested only ZIP archive since I don't know what other formats Windows Shell supports this way). TheContent
parameter can be the name of the file or folder that you want to include to the given archive file. Usage can be like this. The first call shows how to copy file to the archive, the second how to copy folder:The
CopyHere
method also provides a set of options, by which you can refine behavior of this method. Since I'm not sure which options can be used for archives and since there's a lot of combinations, I'll just post here their translation and the way how to use them keeping their (optional) usage on you (for more information see the linked MSDN reference):