!/usr/bin/env python
-- coding:utf-8 --
@Author : yumingquan
python 脚本
import shutil,os,sys
def get_dir(path,fileType):
#查看当前目录文件列表(包含文件夹)
allfilelist = os.listdir(path)
for file in allfilelist:
filepath = os.path.join(path, file)
#判断是否是文件夹,如果是则递归遍历
if os.path.isdir(filepath):
get_dir(filepath,'x.png')
else:
if filepath.endswith(fileType):
copyPath = filepath.replace(targetPath,distPath)
copyDir = os.path.dirname(copyPath)
if not os.path.exists(copyDir):
os.makedirs(copyDir)
shutil.move(filepath, copyPath)
if __name__ == '__main__':
targetPath = sys.argv[1]
distPath = os.getcwd()
get_dir(targetPath,'x.png')
网友评论