title: How do I build an os.system() command using a Path object + string?
body: <p>I'm trying to write a script that pulls in some paths from a config file and invokes the system shell to run a command using the path as part of the command.  It's basically a digest script that unrars all files in a directory.  Please keep in mind, I am teaching myself Python, this is my first python script and this is my first post.  Please excuse any mistakes in etiquette on my part.</p>
  
  <p>The goal is to get the command 'C:\Program Files\WinRAR\Rar.exe x' to run on a directory.  Unfortunately, I've learned that Python doesn't let you concatenate a string to a Path object, presumably because they are two different element types.  I have the following:</p>
  
  <p>In config file:</p>
  
  <pre><code>[Paths]
  WinrarInstallPath = C:\Program Files\WinRAR\
  NewFilesDirectory = M:\Directory\Where\Rar Files\Are\Located
  </code></pre>
  
  <p>Script:</p>
  
  <pre class="lang-py prettyprint-override"><code>**SOME CODE***
  new_files_dir = Path(config.get('Paths', 'NewFilesDirectory'))
  winrar_dir = Path(config.get('Paths', 'WinrarInstallPath'))
  
  **SOME MORE CODE**
  os.chdir(new_files_dir)
  for currentdir, dirnames, filenames in os.walk('.'):
      os.system(winrar_dir + "rar.exe x " + os.getcwd() + currentdir[1:] + '\\*.rar')
  </code></pre>
  
  <p>Which gives me the error "TypeError: unsupported operand type(s) for +: 'WindowsPath' and 'str'"</p>
  
  <p>I've tried</p>
  
  <pre class="lang-py prettyprint-override"><code>os.system(str(winrar_dir) + "rar.exe x " + os.getcwd() + currentdir[1:] + '\\*.rar')
  </code></pre>
  
  <p>but it doesn't handle the spaces in the directory names.  I've also tried</p>
  
  <pre class="lang-py prettyprint-override"><code>os.system(os.path.join(winrar_dir, "rar.exe x ") + os.getcwd() + currentdir[1:] + '\\*.rar')
  </code></pre>
  
  <p>with the same result</p>
  
  <p>I realize I can treat it as a string from the beginning and do the following</p>
  
  <pre class="lang-py prettyprint-override"><code>wrd = config.get('Paths', 'WinrarInstallationPath')
  winrar_dir = '"' + wrd + '"'
  
  os.system(winrar_dir + "rar.exe x " + os.getcwd() + currentdir[1:] + '\\*.rar')
  </code></pre>
  
  <p>but Python has been pretty slick so far and this just feels very clumsy, so I feel like I'm missing something, but I haven't been able to find an answer so far.</p>