1

What would be the best way to have 'file' returned as a string to be read into shell.Run()?

for dirpath, subdirs, files in os.walk(SOMEDIR):
    for ext in files:
        if ext.endswith(".txt"):

            file = str(os.path.join(dirpath, ext))

            shell = win32com.client.Dispatch('WScript.Shell')
            os.chdir(PROGDIR)
            shell.Run(PROG + file)

The issue I'm having is 'file' is not in a format that shell.Run() can read because there is a space in the dirpath. i.e. (Z:\Some Directory\etc\etc). Renaming the directory is not an option.

Jack of Hearts
  • 63
  • 2
  • 10
  • 3
    Can you put quotes around it before passing it in? – BrenBarn Mar 06 '14 at 04:09
  • @BrenBarn could you be more specific? Put quotes around what exactly? String slice up file? – Jack of Hearts Mar 06 '14 at 04:13
  • Please take a look at [this SO answer](http://stackoverflow.com/a/7262918/3219121) – matagus Mar 06 '14 at 04:27
  • 1
    the string needs to be exactly like the console - you can't do e.g. `c:> c:\program files\myprog\prog.exe` in the console either, if you try it, tab completion will change it to `c:> "c:\program files\myprog\prog.exe" arg1 arg2` etc... – Corley Brigman Mar 06 '14 at 04:51

0 Answers0