擅长:python、mysql、java
<p>正如anttihaapala在一篇评论中提到的,脚本不会在符号链接上中断,而是在<em>断开的symlinks</em>上中断。避免这种情况的一种方法是使用<code>try/except</code>:</p>
<pre class="lang-py prettyprint-override"><code>#! /usr/bin/python2
import os
import sys
space = 0L # L means "long" - not necessary in Python 3
for root, dirs, files in os.walk(sys.argv[1]):
for f in files:
fpath = os.path.join(root, f)
try:
space += os.stat(fpath).st_size
except OSError:
print("could not read "+fpath)
sys.stdout.write("Total: {:d}\n".format(space))
</code></pre>
<p>作为一个副作用,它提供了关于可能断开的链接的信息。在</p>