我已将所有需要导入数据库的 shapefile 放在一个文件夹中。我写了一个脚本,shapefile 被导入到数据库中。现在我需要在上传后将这些 shapefile 移动到另一个文件夹。(数据文件将具有相同的名称,但扩展名不同,例如roads.dbf、roads.shp、roads.prj、roads.shx 等)上传后我面临移动这些文件的问题。我编写了一个完整的代码要移动的文件夹。请帮助我。先感谢您 !
import os, subprocess,shutil
os.environ['PATH'] += r';C:\Program Files\PostgreSQL\9.6\bin'
os.environ['PGHOST'] = 'localhost'
os.environ['PGPORT'] = '5432'
os.environ['PGUSER'] = 'postgres'
os.environ['PGPASSWORD'] = '****'
os.environ['PGDATABASE'] = 'postgres'
base_dir = r"c:\data"
full_dir = os.walk(base_dir)
shapefile_list = []
for source, dirs, files in full_dir:
for file_ in files:
if file_[-3:] == 'shp':
shapefile_path = os.path.join(base_dir, file_)
shapefile_list.append(shapefile_path)
for shape_path in shapefile_list:
cmds = 'shp2pgsql "' + shape_path + '" | psql '
subprocess.call(cmds, shell=True)
src="c:\data"
dst = "c:\destination"
shutil.move(src, dst)