python3 移動文件


 

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))

 

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM