#!/usr/bin/python
#Author: lad
#function list all file in the dir
#date 2016-10-11
import os
import sys
def print_files(path):
lsdir = os.listdir(path)
dirs = [i for i in lsdir if os.path.isdir(os.path.join(path,i))]
files = [i for i in lsdir if os.path.isfile(os.path.join(path,i))]
if dirs:
for d in dirs:
print_files(os.path.join(path,d))
if files:
for f in files:
print os.path.join(path,f)
print_files(sys.argv[1])
注意:递归的使用
使用os.path.join拼接文件的路径。
欢迎打算使用阿里云服务器的小伙伴,加我私聊!!QQ:3533470970 或直接领取阿里云幸运券:https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=b6h928qb&utm_source=b6h928qb
转载于:https://blog.51cto.com/liqilong2010/1860886