zoukankan      html  css  js  c++  java
  • 复制文件到每一文件夹中 with python

    def add_file_dirs(src_file, des_dir_path):
        """将文件添加到指定文件夹中的所有目录中
    
        Args:
            src_file (str): 要添加的文件路径
            des_dir_path (str): 被添加文件的路径
        """
        dir_names=os.listdir(des_dir_path)
        for i in dir_names:
            temp_dir = des_dir_path+"/"+i
            if os.path.isdir(temp_dir):
                des_file_path = temp_dir+"/"+os.path.basename(src_file)
                copyfile(src_file,des_file_path)
                print(src_file + " -> " +  des_file_path)
    
    
    

    测试:

    if __name__ == '__main__':
        shell_file='./shell_test.sh'
        add_file_dirs(src_file=shell_file, des_dir_path=to_dir)
    

    原结构是:

    dir_sql/
    ├── 1
    │   └── test1.sql
    ├── 2
    │   └── test2.sql
    ├── 3
    │   └── test3.sql
    └── 4
        └── test4.sql
    

    运行后结构是:

    dir_sql/
    ├── 1
    │   ├── shell_test.sh
    │   └── test1.sql
    ├── 2
    │   ├── shell_test.sh
    │   └── test2.sql
    ├── 3
    │   ├── shell_test.sh
    │   └── test3.sql
    └── 4
        ├── shell_test.sh
        └── test4.sql
    
  • 相关阅读:
    GIT操作远程仓库
    GIT基本使用方式
    Docker网络及私有仓库配置
    Docker容器资源控制
    Docker基本使用方法
    [linux Tcmd] sh source
    hh
    推演论
    智能小车项目计划
    [CATARC_2017S] Week2
  • 原文地址:https://www.cnblogs.com/heenhui2016/p/13803933.html
Copyright © 2011-2022 走看看