首页 > 解决方案 > 是否可以使用 Python 将 Geopackage 文件移动到另一个文件夹?

问题描述

信息

我使用 QGIS 执行了批处理,因此有许多 Geopackage (gpkg) 文件分布在多个文件夹中。因此,我想搜索包含特定字符串的所有文件以自动对它们进行排序。我整理了来自不同来源的代码。我会很高兴任何提示!

代码

该代码完美运行,它打印目录中包含的正确文件。

import os
import shutil

copyDir = 'Folder to move files to'
copyDirAbs = os.path.abspath(copyDir)

searchDir  = 'Directory that contains all folders to search through'
searchDirAbs = os.path.abspath(searchDir)

for path, currentDirectory, files in os.walk(searchDirAbs):
    for file in files:
        if file.__contains__("String"):
            print(file)

不起作用的代码

如果无论如何尝试使用 shutil.move 或 .copy 扩展循环,就会出现FileNotFoundError。该函数在某种程度上与目录混淆了,或者它是否可能不适用于 .gpkg?

for path, currentDirectory, files in os.walk(searchDirAbs):
    for file in files:
        if file.__contains__("String"):
            totalCopyPath = os.path.join(searchDirAbs, file)
            shutil.move(file, totalCopyPath, copyDirAbs)

标签: pythonoperating-systemshutilgeopackage

解决方案


推荐阅读