python - 是否可以使用 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)
解决方案
推荐阅读
- javascript - React - 条件渲染(来自多个数组的迭代)
- c - 在不同环境下运行C程序时出现段错误
- python - 无法使用 Pyads 建立路由(Python 和 TwinCAT 3)
- python-2.7 - 在python中按位转移到正确的问题
- android - 我的 sqLite 光标在循环结束时运行并生成 CursorIndexOutOfBoundsException
- aws-appsync - 如何判断哪个 API 正在使用我的解析器模板?
- css - 为什么当我使用背景时: url() 我的图像从不显示?
- function - 如何根据特定列中的值更改函数
- c - 尝试访问嵌套结构并出现分段错误
- python - 使单选按钮只添加一次,而不是每次点击添加 1