Python directory under all subdirectories move files to the new List

Python directory under all subdirectories move files to the new List

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('移动完成')

  

Guess you like

Origin www.cnblogs.com/68xi/p/11665951.html