This commit is contained in:
岛风 2024-06-27 02:25:47 +08:00
parent c64c2f3581
commit 48c0b1f0ee

View File

@ -35,14 +35,18 @@ def save_urls(urls, output_file, root_folder):
"""将URL链接保存到YAML文件中""" """将URL链接保存到YAML文件中"""
with open(output_file, 'w', encoding='utf-8') as f: with open(output_file, 'w', encoding='utf-8') as f:
f.write(f"{root_folder}:\n") f.write(f"{root_folder}:\n")
for dir_name, files in urls.items(): if has_subdirectories(urls):
if dir_name == '.': for dir_name, files in urls.items():
for file in files: if dir_name == '.':
f.write(f" {file}\n") for file in files:
else: f.write(f" {file}\n")
f.write(f" {dir_name.split('/')[-1]}:\n") else:
for file in files: f.write(f" {dir_name.split('/')[-1]}:\n")
f.write(f" {file}\n") for file in files:
f.write(f" {file}\n")
else:
for file in urls['.']:
f.write(f" {file}\n")
def parse_arguments(): def parse_arguments():
"""解析命令行参数""" """解析命令行参数"""
@ -65,6 +69,10 @@ def list_files_recursive(start_path='.', exclude_files=None):
file_paths.append(os.path.join(root, file)) file_paths.append(os.path.join(root, file))
return file_paths return file_paths
def has_subdirectories(urls):
"""检查是否存在子文件夹"""
return any(dir_name != '.' for dir_name in urls)
def main(): def main():
args = parse_arguments() args = parse_arguments()
current_script = os.path.basename(__file__) current_script = os.path.basename(__file__)