How to copy folder structure under another directory?

后端 未结 3 1348
日久生厌
日久生厌 2021-02-15 23:51

I have some questions related to copying a folder structure. In fact, I need to do a conversion of pdf files to text files. Hence I have such a folder structure for the place wh

3条回答
  •  深忆病人
    2021-02-16 00:26

    How about using shutil.copytree()?

    import shutil
    def ig_f(dir, files):
        return [f for f in files if os.path.isfile(os.path.join(dir, f))]
    
    shutil.copytree(inputpath, outputpath, ignore=ig_f)
    

    The directory you want to create should not exist before calling this function. You can add a check for that.

    Taken from shutil.copytree without files

提交回复
热议问题