擅长:python、mysql、java
<p>下面是Blender <a href="https://stackoverflow.com/questions/16910330/return-number-of-files-in-directory-and-subdirectory">here</a>建议的一种方法。
def fileCount(文件夹):
“计算目录中的文件数”</p>
<pre><code>count = 0
for filename in os.listdir(folder):
path = os.path.join(folder, filename)
if os.path.isfile(path):
count += 1
elif os.path.isfolder(path):
count += fileCount(path)
return count
</code></pre>
<p>这被包装在一个函数中。但你需要澄清你所说的“最好”是什么意思。那是最快的吗?最具可读性?记忆最差?你知道吗</p>