【发布时间】:2019-12-15 20:04:21
【问题描述】:
假设我有以下文件夹,名为 local,我想使用 python 3.7 和 shutil 库对其进行递归复制。 local 文件夹始终具有相同的内部结构。
.
├── local/
├── A/
| ├── img/
| | ├── 1.jpg
| | ├── ...
| | └── n.jpg
| |
| └── txt/
| ├── text_1.txt
| ├── ...
| └── text_n.txt
├── B/
. ├── img/
. | ├── 1.jpg
. | ├── ...
| └── n.jpg
|
└── txt/
├── text_1.txt
├── ...
└── text_n.txt
使用shutil库和它的copy方法,如果想得到下面的remote结构,怎么写ignore_patterns参数(递归忽略每个子文件夹中的img文件夹 ):
.
├── remote/
├── A/
| └── txt/
| ├── text_1.txt
| ├── ...
| └── text_n.txt
├── B/
. └── txt/
. ├── text_1.txt
. ├── ...
└── text_n.txt
天真地,我尝试了shutil.copytree('local', 'remote', ignore=shutil.ignore_patterns('local/*/img')),但没有成功。
【问题讨论】: