Python将某文件夹及其子文件夹下某种格式的文件移动到另一个指定的文件下

import shutil,os
new_path='/root/python_test/data/gp_fz'
for derName, subfolders, filenames in os.walk('/root/python_test/data/gp'):
    print(derName)
    print(subfolders)
    print(filenames)
    for i in range(len(filenames)):
        if filenames[i].endswith('.xls'):
            file_path=derName+'/'+filenames[i]
            newpath=new_path+'/'+filenames[i]
            shutil.copy(file_path,newpath)

你可能感兴趣的:(Python)