※ 引述《shihyu (shihyu)》之铭言:
: 我有1万张图片大约有5G容量, 想把这1万张图每2G分成一个资料夹
: 请问一下有什么linux 指令可以做到?
: 谢谢
#!/bin/env python3
from pathlib import Path
import os
import shutil
number=0
current_size=0
pattern = "new-folder-%03d"
new_directory = pattern % number
Path(pattern % number).mkdir(parents=True, exist_ok=True)
# 默认抓 /path/picture/* 该目录内档案,若是要包含子目录,请使用像是 rglob('*.jpg') 替代
for item in Path('/path/picture/').glob('*'):
current_size+=item.stat().st_size
if current_size >= 1024 * 1024 * 3:
number+=1
current_size = 0
new_directory = pattern % number
Path(new_directory).mkdir(parents=True, exist_ok=True)
shutil.move(os.path.join(item.parent, item.name), os.path.join(new_directory, item.name))
直觉写的 code,用 python 语言。提供参考。里面路径与档案大小可以自行调整。