python 操作文件非常简单,却也非常高效!
此次,主要写遍历文件:
#copy the file with directory,and search all of the file's with path
def search_file(src,dst):
file_list = []
if src is None:
raise Exception('source_path is None')
#if dst is not None:
# raise Exception('dest_path has existed')
print src
print dst
shutil.copytree(src,dst)
for dirpath,dirnames,filenames in os.walk(dst):
for name in filenames:
file_list.append(dirpath + '\\' + name)
return file_list
小小说明
我们操作文件,最好使用shutil这个库,高效方便
而,os.walk也非常好用