# 3. 获取所有图片文件并排序
supported_formats = ('.jpg', '.jpeg', '.png', '.gif', '.webp')
image_files = []
for f in os.listdir(image_folder):
if f.lower().endswith(supported_formats) and not f.startswith('._'):
image_files.append(f)
image_files.sort(key=natural_sort_key) # 按文件名排序
if not image_files:
print("错误:指定文件夹中没有找到支持的图片文件。")
return
def walk_pathlib(path: Path, max_depth: int = -1, current_depth: int = 0):
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
full_path = os.path.join(dirpath, filename)
print(f"[文件] {full_path}")
for dirname in dirnames:
full_path = os.path.join(dirpath, dirname)
print(f"[子目录] {full_path}")
create_epub(full_path, dirname)
current_depth+=1
if max_depth != -1 and current_depth > max_depth:
break
def main():
user_input = input("请输入文件夹路径:").strip()
folder = Path(user_input)
name = folder.name
if not folder.is_dir():
print(f"路径错误:{folder}")
return
print(f"路径:{folder}")
print(f"文件夹:{name}")
if not any(p.is_dir() and not p.name.startswith('.') for p in folder.iterdir()):
return create_epub(str(folder), name)
else:
return walk_pathlib(folder, max_depth=0)