How can I check how much of a path exists in python
<p>Let's say on my filesystem the following directory exists:</p>

<pre><code>/foo/bar/
</code></pre>

<p>In my python code I have the following path:</p>

<pre><code>/foo/bar/baz/quix/
</code></pre>

<p>How can I tell that only the <code>/foo/bar/</code> part of the path exists? </p>

<p>I can walk the path recursively and check it step by step, but is there an easier way?</p>

<p>I don't actually get your requirements as whether you want every path to be checked or upto some specific level.But for simple sanity checks you can just iterate through the full path create the paths and check the sanity.</p>

<pre><code>for i in filter(lambda s: s, sample_path.split('/')):
  _path = os.path.join(_path, i)
   if os.path.exists(_path):
      print "correct path"
</code></pre>

python path directory