Python - Is there a way around 'os.listdir()' returning gibberish for bad folder name?
<p>I have a simple script written in Python:</p>

<pre><code>import os

def Path(SourcePath):
    for Folder in os.listdir(SourcePath):
     print "TESTING: %s" % Folder

Path("\\\\192.168.0.36\\PDFs")
</code></pre>

<p>When i run this it recurses through a remote share on the LAN and just simply displays the names of the folders found. This share primarily contains folders.</p>

<p>The problem is that if a folder name has a space at the end of it's name, the above script lists jibberish.</p>

<p>For example, if i have the following folders in the above share:</p>

<ol>
<li>"6008386 HH - Walkers Crisps"</li>
<li>"6008157 CPP - Santas Chocolate "</li>
<li>"6007458 SCA - Morrisons Bananas"</li>
</ol>

<p>Notice that "6008157 CPP - Santas Chocolate " has a space at the end. This is the listing from the above script:</p>

<ol>
<li>"TESTING: 6008386 HH - Walkers Crisps"</li>
<li>"TESTING: 6EBA72~1"</li>
<li>"TESTING: 6007458 SCA - Morrisons Bananas"</li>
</ol>

<p>How can i avoid this while recursing the remote dir? I could fix the folder name if only it was returned properly by 'os.listdir()'.</p>

<p>Any ideas on how to tackle this?</p>
