import os
import datetime
from datetime import timedelta
def create_date_folders():
"""自动生成从 2025.10.22 到 2025.11.14 的日期文件夹"""
print("=== 自动生成日期文件夹工具 ===\n")
# 获取用户输入的路径
base_path = input("请输入要创建文件夹的路径:").strip()
if not base_path:
print("未输入路径,程序退出")
return
# 检查路径是否存在
if not os.path.exists(base_path):
print(f"路径不存在:{base_path}")
create_choice = input("是否要创建该路径?(y/n): ").strip().lower()
if create_choice == 'y':
try:
os.makedirs(base_path)
print(f"已创建路径:{base_path}")
except Exception as e:
print(f"创建路径失败:{e}")
return
else:
print("程序退出")
return
# 设置起始和结束日期
start_date = datetime.date(2025, 10, 22)
end_date = datetime.date(, , )
()
()
()
confirm = ().strip().lower()
confirm != :
()
current_date = start_date
created_count =
existing_count =
()
current_date <= end_date:
folder_name =
folder_path = os.path.join(base_path, folder_name)
:
os.path.exists(folder_path):
os.makedirs(folder_path)
()
created_count +=
:
()
existing_count +=
Exception e:
()
current_date += timedelta(days=)
()
()
()
()
created_count > :
first_folder =
last_folder =
()
():
()
base_path = ().strip()
base_path:
()
os.path.exists(base_path):
()
create_choice = ().strip().lower()
create_choice == :
:
os.makedirs(base_path)
()
Exception e:
()
:
()
start_date = datetime.date(, , )
end_date = datetime.date(, , )
()
()
()
()
()
()
format_choice = ().strip()
confirm = ().strip().lower()
confirm != :
()
current_date = start_date
created_count =
existing_count =
()
weekday_map = {
: ,
: ,
: ,
: ,
: ,
: ,
:
}
current_date <= end_date:
format_choice == :
weekday_chinese = weekday_map[current_date.weekday()]
folder_name =
:
folder_name =
folder_path = os.path.join(base_path, folder_name)
:
os.path.exists(folder_path):
os.makedirs(folder_path)
()
created_count +=
:
()
existing_count +=
Exception e:
()
current_date += timedelta(days=)
()
()
()
()
():
()
()
()
choice = ().strip()
choice == :
create_date_folders_with_weekday()
:
create_date_folders()
()
__name__ == :
main()
Python
Python 自动批量创建日期文件夹
一个使用 Python 编写的脚本,用于根据指定时间范围自动批量创建日期格式的文件夹。脚本支持两种命名格式(简单日期或包含星期几),具备路径检查与创建功能,并能统计创建结果。适用于需要按日期归档文件的场景。

