neazoi

Problem in compressing file using external program due to spaces in file location

3 posts in this topic

#1 ·  Posted (edited)

Hi here is a snippet of my code that uses 7zip (external compression program) to compress a file selected from a previous dialogue. The file and location to be compressed is passed into $sFileOpenDialog and then the command to be run for the 7zip is created.

The problem is that if the $sFileOpenDialog value contains spaces, the 7zip command fails to run.

When I run the command manually (run the exe by hand from the windows command prompt) the spaces in the filename/location do not affect the compression

Any help of how to solve this?

;$sFileOpenDialog2 is the tmp.zip file and its path
               Local $sFileOpenDialog2 = @TempDir&"\tmp.zip"

               ;compress the file selected
               ;First check if tmp.zip file exists
                Local $iFileExists = FileExists($sFileOpenDialog2)
                
                ; Check if file exists or not.
                If $iFileExists Then
                   
                     ;Delete the temporary tmp.zip file.
                     FileDelete($sFileOpenDialog2)
                     ;Set the parameters of the create zip command
                     Local $param1 = @ScriptDir&"\7z.exe "
                     Local $param3 = "a -tzip -aoa -mx=9 "
                     Local $param4 = @TempDir&"\tmp.zip "
                     ;Create zip
                    RunWait($param1&$param3&$param4&$sFileOpenDialog, "", @SW_HIDE)

                Else

                    ;Set the parameters of the create zip command
                     Local $param1 = @ScriptDir&"\7z.exe "
                     Local $param3 = "a -tzip -aoa -mx=9 "
                     Local $param4 = @TempDir&"\tmp.zip "
                     ;Create zip
                    RunWait($param1&$param3&$param4&$sFileOpenDialog, "", @SW_HIDE)

                 EndIf

 

Edited by neazoi

Share this post


Link to post
Share on other sites



Try add double quotes around the string returned by FileOpenDialog

$sFileOpenDialog = '"' & $sFileOpenDialog2 & '"'

 

Share this post


Link to post
Share on other sites
1 hour ago, InunoTaishou said:

Try add double quotes around the string returned by FileOpenDialog

$sFileOpenDialog = '"' & $sFileOpenDialog2 & '"'

 

It worked like a charm!

Many thanks!!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now