Skip to content

Dytchem/Copy-Helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

generate.py - 批量格式化复制文件/文件夹

批量处理文件夹或文件,根据字典中的列表值替换占位符并生成多个副本。

功能特点

  • ✅ 智能占位符替换:自动替换文件名和内容中的 [key] 占位符
  • ✅ 保留目录结构:复制时保留原始文件夹结构
  • ✅ 严格长度验证:确保所有列表长度一致

快速开始

1. 创建配置文件 (config.py)

def dic():
    return {
        'name': ['0', '1', '2'],
        'color': ['red', 'blue', 'green']
    }

2. 准备源文件结构

[name]/report_[color].txt
[name]/subfolder/data_[name].txt

3. 运行程序

python generate.py [name] target config.py

4. 生成结果

target/0/report_red.txt
target/0/subfolder/data_0.txt
target/1/report_blue.txt
target/1/subfolder/data_1.txt
target/2/report_green.txt
target/2/subfolder/data_2.txt

使用说明

命令格式

python generate.py <path0> <path1> <path_py>
参数 说明
path0 源文件夹或文件(可包含占位符)
path1 目标目录
path_py 包含 dic() 函数的Python文件

字典要求

  • 所有列表长度必须一致
  • 占位符格式:[key]
  • 未找到的key会被原样保留

错误处理

错误类型 解决方案
字典为空 确保 dic() 返回非空字典
列表长度不一致 确保所有列表长度相同
源路径不存在 检查 path0 路径是否存在
缺少 dic() 函数 确保 path_py 包含 dic() 函数

About

批量格式化复制文件/文件夹

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages