0

I have put all the shapefiles that need to be imported to database in a folder. i wrote a script and the shapefiles are been imported to the database. now i need those shapefiles to be moved to another folder after the upload. (the data files would have same name with different extension for example roads.dbf,roads.shp,roads.prj,roads.shx etc. ) i facing problem to move these files after the upload.I wrote a code which is making whole folder to move. Please help me in this. Thank you in Advance !

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)
stc07stc
  • 1
  • 1

0 Answers0