python移动目录下所有子目录文件到新的总目录

python移动目录下所有子目录文件到新的总目录

import os
import shutil
def file(p):
    p=p
    z=os.listdir(p)
    for i in z:
        if not (os.path.isfile(os.path.join(p,i))):
            pp=os.path.join(p,i)
            file(pp)
        else:
            zz=os.listdir(p)
            for k in zz:
                paa.append(os.path.join(p,k))
if __name__ == '__main__':
    p = 'F:\meizhuo'
    n_p = 'F:\zmeizhuo'
    paa = []
    file(p)
    for f in paa:
        try:
            shutil.move(f,n_p)
        except:
            continue
    print('移动完成')

  

posted @ 2019-10-13 12:44  圆柱模板  阅读(1625)  评论(0编辑  收藏  举报