2017-02-13 22 views

答えて

1

これはあなたのために働く可能性があります -

import os 
import datetime as dt 
import shutil 


now = dt.datetime.now() 
ago = now-dt.timedelta(minutes=30) #Mention the required time 

for root, dirs,files in os.walk('/home/piyush/pppptest'): #put required directory path 
    for fname in files: 
     path = os.path.join(root, fname) 
     st = os.stat(path)  
     mtime = dt.datetime.fromtimestamp(st.st_mtime) #Gives you the modified time of file 
     # print mtime 
     if mtime > ago: 
      print('%s modified %s'%(path, mtime)) #You can check path and modified and work on it as per your requirement 
      shutil.rmtree('path') #You can delete it. 
1

あなたはこの

のような最新のフォルダを見つけることができます
import os, shutil 

newest_folder = max(folders, key=os.path.getmtime) 

for fname in folders: 
    if fname != newest_folder: 
     shutil.rmtree(folder) 

あなたは、あなたの正確な要件

に応じて、代わりに getmtimegetctimeを使用する場合があります
関連する問題