[Tutor] Why is this not working? Seems like a whitespace issue

Necmettin Begiter necmettin.begiter at gmail.com
Mon Feb 5 09:41:30 CET 2007


05 Şub 2007 Pts 04:58 tarihinde, Gizmo şunları yazmıştı: 
> Hello
> I have a whole directory tree of RAR files that I wish to extract as a
> batch job. In my real script I've used os.walk() and os.spawn*() but for
> demonstration purposes have a look at the code below
>
> >>> import os
> >>> process=r"C:\Program Files\WinRAR\Rar.exe"
> >>> startDir = r"C:\to burn"
> >>>
> >>> os.system(process+" x "+"C:\\to burn\\somemovie\\mymovie.rar"+"
>
> "+startDir)
>
> This doesnt work for me.. I get the error "  'C:\Program' is not recognized
> as an internal or external command, operable program or batch file."
> Notice that it says "C:\Program".... thats the incorrect path, the path is
> supposed to be "C:\Program Files\..."
>
> I realised the problem definitely because of the space between "Program"
> and "Files"..
> Actually, I even know the solution to an extend. In Windows command prompt,
> whenever you have whitespaces in your path, you are expected to enclose the
> whole path in double quotes; for example:
>
> C:\>rar.exe x "C:\to burn\blah blah\"
>
> I think this is the reason, but I am unsure. Your support is greatly
> appreciated.
>
> Thanks!
Do you actually need the strings to be "raw"? (r"")
Converting those strings to normal strings, you could easily make sure the 
space character (#32) is taken into account by escaping it:
process= "c:\\Program\ files\\WinRar\Rar.exe"


More information about the Tutor mailing list