<p>在我的windows7 64位系统中,文件夹<code>c:/windows/system32</code>中有一个名为<code>msconfig.exe</code>的文件。是的,它一定存在。</p>
<p>但是当我使用<code>os.listdir</code>搜索文件夹<code>c:/windows/system3</code>2时,我没有得到文件。这是测试代码,在<code>t1.py</code>:</p>
<pre><code>import os
files = os.listdir("c:/windows/system32")
for f in files:
if f.lower() == "msconfig.exe":
print(f)
</code></pre>
<p>在运行python<code>t1.py</code>之后,我什么也得不到。
为什么文件漏了?如何列出文件夹下的所有文件?</p>
<p>顺便说一下:我在Windows764bit下使用的是Python3.3.032bit版本</p>
<p>尝试:<code>C:\Windows\System32</code>而不是<code>c:/windows/system32</code></p>
<pre><code>import os,sys
files = os.listdir('C:\Windows\System32')
for x in files:
if x == ('msconfig.exe'):
print(x)
</code></pre>