将指定文件从某个目录(支持子目录遍历)复制到指定文件夹下:
import os
import shutil
def copyFile(oldPath,newPath,fileType):
if not oldPath.endswith('/'):
oldPath += '/'
if not newPath.endswith('/'):
newPath += '/'
fileList=[]
for root,dirs,files in os.walk(oldPath):
print('[+] '+root)
for filename in files:
if filename.endswith(fileType):
print('deeling:',root+'/'+filename)
fileList.append([root+'/'+filename,newPath+filename])
for f in fileList:
print('copying:', f[0])
shutil.copyfile(f[0],f[1])
if __name__ == '__main__':
copyFile('D:\\penetration\\origin','D:\\penetration\\dest','.jar')