小编sur*_*itt的帖子

使用 Python 从多个文件夹中提取所有文件

我写下了这段代码:

import shutil

files = os.listdir(path, path=None)
for d in os.listdir(path):
    for f in files:
        shutil.move(d+f, path)
Run Code Online (Sandbox Code Playgroud)

我希望给定目录 ( path)中的每个文件夹都包含文件,将该文件夹中包含的文件移动到包含该文件夹的主目录 ( path) 中。

例如:此文件夹中的文件: C:/example/subfolder/ 将被移入: C:/example/

(并且该目录将被删除。)对不起,我的英语不好:)

python python-3.x

1
推荐指数
1
解决办法
2850
查看次数

标签 统计

python ×1

python-3.x ×1