Here is an example batch script
(zipScript.bat)
@echo off
setlocal
rem First parameter - path to dir to be zipped
rem Second parameter- zip file name
set sourceDir=%1
set zipFile=%2
rem Create PowerShell script
echo Write-Output 'Custom PowerShell profile in effect!' > %~dp0TempZipScript.ps1
echo Add-Type -A System.IO.Compression.FileSystem >> %~dp0TempZipScript.ps1
echo [IO.Compression.ZipFile]::CreateFromDirectory('%sourceDir%','%~dp0%zipFile%') >> %~dp0TempZipScript.ps1
rem Execute script with flag "-ExecutionPolicy Bypass" to get around ExecutionPolicy
PowerShell.exe -ExecutionPolicy Bypass -Command "& '%~dp0TempZipScript.ps1'"
del %~dp0TempZipScript.ps1
endlocal
I run it in windows CMD like this:
F:\stuff\godot\etc\bin\windows\zip\zipScript.bat F:\stuff\godot\etc\bin\windows\zip\test11 result.zip
and it generates a (result.)zip file from a folder(test11).
Note that when I run it, in CMD, I do not use any quotes!
Now trying to do this through gdscript, I try:
func _ready():
zipArchive('F:\\stuff\\godot\\etc\\bin\\windows\\zip\\test11','result.zip')
var zipScript = "F:\\stuff\\godot\\etc\\bin\\windows\\zip\\zipScript.bat"
func zipArchive(targetFolderPath,zipFileName):
if OS.get_name() =='Windows':
print("ZIP script:",zipScript)
var output = []
OS.execute(zipScript,[targetFolderPath,zipFileName],true,output)
print(output)
Nothing happens, and godot prints out the following:
ZIP script:F:\stuff\godot\etc\bin\windows\zip\zipScript.bat
[[IO.Compression.ZipFile]::CreateFromDirectory('"F:\stuff\godot\etc\bin\windows\zip\test11"','F:\stuff\godot\etc\bin\windows\zip\"result.zip') >> F:\stuff\godot\etc\bin\windows\zip\TempZipScript.ps1
Custom PowerShell profile in effect!
Note how the output has extra quotation marks around the parameters
Godot seems to be adding quotation marks to the arguments, however my batch script requires the parameters to have no quotation marks - they break the script
PS: Btw I am doing this hacky zip business, because godot has no zip/unzip functionality exposed to gdscript, and the batch script is the smallest filesize solution I managed to find
You should fix your script to support string arguments between double quotes. What if your path was F:\stuff\godot engine\? Double quotes are necessary to delimit string arguments while allowing the use of spaces in the string itself.
@akien-mga
Ah sorry, I was using the wrong syntax. This fixed the problem btw:
set sourceDir=%sourceDir:"=%
set sourceDir=%sourceDir:'=%
set zipFile=%zipFile:"=%
set zipFile=%zipFile:'=%
But it was an external fix, not possible to do inside godot! What if instead of batch script, I had to deal with a binary executable that didnt allow me to change its design, and the design required parameters without quotes?
Never wrote a PowerShell script, but I'm pretty sure that you can just remove the single quotes in [IO.Compression.ZipFile]::CreateFromDirectory('%sourceDir%','%~dp0%zipFile%') and just pass the strings.
@akien-mga removing the single quotes didnt fix it - that was the first thing I tried btw
But it was an external fix, not possible to do inside godot! What if instead of batch script, I had to deal with a binary executable that didnt allow me to change its design, and the design required parameters without quotes?
Well what I mean is that your script is badly designed. Any command line application should be able to support strings with double quotes.
Try it in cmd.exe:
cd C:\Users\<your name>\Local^ Settings
cd "C:\Users\<your name>\Local Settings"
Both are equivalent. The second has the advantage that you don't need to escape spaces. (If you tab complete, it's even quoted automatically).
@akien-mga I agree with you it is a bad design, I took the script from a stackoverflow discussion, but had to alter it in order to get it to work with godot's Os.execute()
Thank you for the help btw, https://github.com/godotengine/godot/issues/11493#issuecomment-331430817 sorted it.
Batch scripts have a strange looking vba syntax
Strangely enough, even with spaces in the path, the script still works when running from within godot
It would be very nice if somebody exposed to gdscript godot's zip/unzip capabilities - that would allow me to ditch these ugly workarounds
Strangely enough, even with spaces in the path, the script still works when running from within godot
Well yes, that's why double quotes are added in the first place :)
It would be very nice if somebody exposed to gdscript godot's zip/unzip capabilities - that would allow me to ditch these ugly workarounds
That's #3701.
Ok I am going to close this bug now. Thank you for the help :)