文件夹路径1包括17个子文件夹每个文件夹内有一个areatif文件将文件夹1内的每个子文件中的areatif文件转移到文件夹2下面
你可以使用Python的shutil库来完成这个任务。首先,你需要导入shutil库:
import shutil
然后,你可以使用os模块的walk函数来遍历文件夹1下的所有子文件夹,并找到每个子文件夹中的"area.tif"文件:
import os
folder1 = "文件夹1的路径"
folder2 = "文件夹2的路径"
for root, dirs, files in os.walk(folder1):
for file in files:
if file == "area.tif":
file_path = os.path.join(root, file)
最后,你可以使用shutil库的move函数将每个"area.tif"文件移动到文件夹2下:
shutil.move(file_path, folder2)
完整的代码如下:
import os
import shutil
folder1 = "文件夹1的路径"
folder2 = "文件夹2的路径"
for root, dirs, files in os.walk(folder1):
for file in files:
if file == "area.tif":
file_path = os.path.join(root, file)
shutil.move(file_path, folder2)
请确保将"文件夹1的路径"和"文件夹2的路径"替换为实际的文件夹路径。
原文地址: https://www.cveoy.top/t/topic/i96J 著作权归作者所有。请勿转载和采集!