Jump to content

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


neazoi
 Share

Recommended Posts

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...