我已经把所有需要导入数据库的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)
目前没有回答
相关问题 更多 >
编程相关推荐