code1
import os import shutil pwd=os.getcwd()
fpath=os.path.join(pwd,"dian") target=os.path.join(pwd,"电子书") c=0 for i in os.listdir(fpath): d=os.path.join(fpath,i) if(os.path.isdir(d)): for j in os.listdir(d): f=os.path.join(d,j) trail=j.split(".")[-1] if(trail=="pdf"): shutil.move(f,target) c+=1 print("移动{}次".format(c))
code2
import os import shutil pwd=os.getcwd() fpath=os.path.join(pwd,"pic") target=os.path.join(pwd,"tmp") c=0 for i in os.listdir(fpath): d=os.path.join(fpath,i) if(i.startswith(".")): continue c+=1 if(os.path.isdir(d)): yulan=os.path.join(d,"yulan") for j in os.listdir(yulan): f=os.path.join(yulan,j) if("mini" in j): shutil.move(d,target) break print("移动{}次".format(c))