我需要编写一个脚本,以移动给定时间后修改的给定父目录内的所有文件夹。我想使用bash或Python。
所以应该是这样的。
forall ${DIR} in ${PARENT_DIR}
If ${DIR} is modified after ${TIME}
move ${DIR} to ${NEW_DIR}
它必须每15分钟检查一次目录的修改,并移动所有新创建的目录。
谢谢您的帮助
import os
from shutil import move
from time import time
def mins_since_mod(fname):
"""Return time from last modification in minutes"""
return (time() - os.path.getmtime(fname)) / 60
PARENT_DIR = '/some/directory'
MOVE_DIR = '/where/to/move'
# Loop over files in PARENT_DIR
for fname in os.listdir(PARENT_DIR):
# If the file is a directory and was modified in last 15 minutes
if os.path.isdir(fname) and mins_since_mod(fname) < 15:
move(fname, MOVE_DIR) # move it to a new location
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句