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