title: Determine if string input could be a valid directory in Python
body: <p>I am writing boilerplate that handles command line arguments that will later be passed to another function. This other function will handle all of the directory creation (if necessary). Therefore my bp only needs to check if an input string <strong>could be</strong> a valid directory, OR a valid file, OR (some other thing). <em>i.e.</em> it needs to differentiate between something like "c:/users/username/" and "c:/users/username/img.jpg"</p>
  
  
  
  <pre class="lang-py prettyprint-override"><code>def check_names(infile):
      #this will not work, because infile might not exist yet
      import os
      if os.path.isdir(infile):
          &lt;do stuff&gt;
      elif os.path.isfile(infile):
          &lt;do stuff&gt;
      ...
  </code></pre>
  
  <p>The standard library does not appear to offer any solutions, but the ideal would be:</p>
  
  <pre class="lang-py prettyprint-override"><code>def check_names(infile):
      if os.path.has_valid_dir_syntax(infile):
          &lt;do stuff&gt;
      elif os.path.has_valid_file_syntax(infile):
          &lt;do stuff&gt;
      ...
  </code></pre>
  
  <p>After thinking about the question while typing it up, I can't fathom a way to check (only based on syntax) whether a string contains a file or directory other than the file extension and trailing slash (both of which may not be there). May have just answered my own question, but if anyone has thoughts about my ramblings please post. Thank you!    </p>