Untitled
Anonymous
plain_text
10/08/2024 3:22 AM
880 B
18
Indexable
import os
# Lấy prefix và đường dẫn từ bàn phím
prefix = input("Nhập prefix: ")
folder_path = input("Nhập đường dẫn đến thư mục chứa ảnh: ")
# Lấy danh sách các file trong thư mục, chỉ lấy file .jpg
file_list = sorted([f for f in os.listdir(folder_path) if f.endswith('.jpg')])
# Đổi tên các file
for i, filename in enumerate(file_list, start=1):
new_name = f"{prefix}_{i:04}.jpg" # Định dạng index thành 4 chữ số
src = os.path.join(folder_path, filename)
dst = os.path.join(folder_path, new_name)
# Đổi tên file
os.rename(src, dst)
print("Đổi tên hoàn tất!")Editor is loading...
Leave a Comment