[ディレクトリの移行] nginx の静的イメージ ディレクトリがいっぱいで、移行する必要がありますが、相対ディレクトリは変更しないでください。

1 か月以上前のビジネス写真を他のマウントされたディスクに移動します

import os  
import shutil
import time
import glob
# 设置源文件夹路径和目标文件夹路径  
source_base_dir = "/data/detector/output/"
target_base_dir = "/databak/output/"
# source_base_dir = "B/"
# target_base_dir = "A/"

for file_path in glob.glob(source_base_dir + "**/*.jpg", recursive=True):
    
    try:
	    file_date = os.path.getmtime(file_path)
	    if file_date < int(time.time() - 30 * 24 * 60 * 60): 
	        target_path =  target_base_dir + file_path[len(source_base_dir)-1:]
	        # shutil.move(file_name, target_path)
	        print("source:"+file_path)
	        dst_parent_dir = os.path.dirname(target_path)
	        if not os.path.exists(dst_parent_dir):  
	            os.mkdir(dst_parent_dir)
	        print("dest:"+target_path)
	        shutil.move(file_path, target_path)
	except:    
    	 traceback.print_exc()

完了するには、画像が削除されているか存在しない場合は、実行を続けます。そうしないと、1.1T のディレクトリの場合、glob.glob イテレータの生成に時間がかかります。

おすすめ

転載: blog.csdn.net/weixin_40293999/article/details/130008877