直接上代码:
import os
path = os.getcwd()
image_count = 1
file_no = 1
for file in os.listdir(path):
if file.split('.')[-1] == 'JPG' or file.split('.')[-1] == 'jpg':
if image_count % 1000 == 1:
os.mkdir(str(file_no))
file_no+=1
image_count+=1
import os
import shutil
path = os.getcwd()
image_count = 0
for file in os.listdir(path):
if file.split('.')[-1] == 'JPG' or file.split('.')[-1] == 'jpg':
image_path = os.path.join(path,file)
folder_no = int(image_count)/1000+1
folder_path = os.path.join(path,str(folder_no))
shutil.move(image_path,folder_path)
image_count+=1
批量移动图片到文件夹
本文提供了一种使用Python批量将大量图片文件(JPG或jpg格式)按每1000张图片创建一个新文件夹并移动进去的方法。首先通过遍历当前目录下所有图片,每累计1000张图片即创建新文件夹;接着再次遍历图片,并根据图片计数将其移动到对应的文件夹中。
1万+





