1

I am trying to unzip a file using Matlab by calling WinRAR through system function of the Matlab. When I gave the path of the WinRAR exe to the system command, I got the folliwng error about the "Program Files" folder:

'C:\Program' is not recognized as an internal or external command, 
operable program or batch file.

My code is as follows:

str = ['C:\Program Files\WinRAR\UnRAR.exe',' ',filename];
system(str)

How may I remove this error about the space between the folder name "Program Files"?

Mushi
  • 367
  • 2
  • 4
  • 14
  • The usage of `system()` results in running in background `%ComSpec% /c` with the string assigned to variable `str` appended as additional arguments. Open a [command prompt](https://www.howtogeek.com/235101/), run `cmd /?` and read the output help which is explaining how the Windows command processor interprets the arguments after option `/C` (or `/K`) and with last paragraph on last output help page that a file name (or folder name or any other argument string) containing a space one of these characters ``&()[]{}^=;!'+,`~`` must be enclosed in `"` to get all characters interpreted literally. – Mofi Dec 16 '20 at 10:14
  • So you have to pass a string to `C:\Windows\System32\cmd.exe` assigned to variable `str` which is in your case `""C:\Program Files\WinRAR\UnRAR.exe" x "filename""`. So there is a `"` at beginning and one more `"` at end. The full qualified file name of `UnRAR` is enclosed also in `"`. `UnRAR.exe` needs a command to execute by `UnRAR` which you have completely forgotten resulting in the error message `Command Line Error: Unsupported command:` output by `UnRAR.exe`. I suggest to use command `x` (extract files with full path). – Mofi Dec 16 '20 at 10:22
  • In command prompt window run `"C:\Program Files\WinRAR\UnRAR.exe" /?` to get output the usage information for this application explaining the syntax to use, which commands can be used and which options (switches) can be used o extracting a RAR archive file. The file name assigned to variable `filename` should be also enclosed in `"` to always work as it is never wrong to enclose a file name argument string in double quotes while it can be wrong not doing that. The file name should be with full path so that the extraction operation does not depend on which directory is the current directory. – Mofi Dec 16 '20 at 10:32
  • PS: If shareware *WinRAR* is installed into `C:\Program Files\WinRAR` and not just freeware `UnRAR.exe`, double click on text file `Rar.txt` in that directory which is the manual for shareware `Rar.exe` and explains more detailed all commands and switches supported also by `UnRAR.exe`. – Mofi Dec 16 '20 at 10:32

1 Answers1

0

Put the path between double quotes:

str = ['"C:\Program Files\WinRAR\UnRAR.exe"',' ',filename];
system(str)
rinkert
  • 6,593
  • 2
  • 12
  • 31
  • I got the following message after applying the double quotes: "Command Line Error: Unsupported command:" – Mushi Dec 16 '20 at 09:05