如果不给出指定目录,则遍历当前目录,得到结果后可以重定向输出。Python代码真简洁啊,主要是库做得好,所以很方便。
from os.path import walk, join, normpath
import sys
from os import getcwd
def mydir(arg, dirname, names):
     files=[normpath(join(dirname, file)) for file in names]
     print "\n".join(files)
if __name__=="__main__":
     if len(sys.argv)==1:
         path=getcwd()
     else:
         path=sys.argv[1]
         walk(path, mydir, 0)
...