Skip to content

Instantly share code, notes, and snippets.

@Guts
Created November 2, 2015 16:28
Show Gist options
  • Save Guts/4c39b4ae888dcebd70cb to your computer and use it in GitHub Desktop.
Save Guts/4c39b4ae888dcebd70cb to your computer and use it in GitHub Desktop.
Add a given .prj dependance to every AutoCAD DWG file found among a given folder structure
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
# -*- coding: UTF-8 -*-
#!/usr/bin/env python
from __future__ import unicode_literals
#------------------------------------------------------------------------------
# Name: OpenCatalog to Excel
# Purpose: Add a given .prj dependance to every AutoCAD DWG file found.
#
# Author: Julien Moura (@geojulien)
#
# Python: 2.7.x
# Created: 02/11/2015
# Updated: --/--/--
#------------------------------------------------------------------------------
###############################################################################
########### Libraries #############
###################################
# Standard library
from os import walk, path # files and folder managing
from shutil import copyfile
###############################################################################
######### Main program ############
###################################
# variables
li_dwg = [] # list of DWG paths
folder_target = r"\\nas.hq.isogeo.fr\SIG\SIG_DATA_SERVICE" # folder structure to search for
prj = r"isogeo_team.prj" # prj file to copy
# listing DWG files
for root, dirs, files in walk(folder_target):
for f in files:
""" looking for files with geographic data """
try:
unicode(path.join(root, f))
full_path = path.join(root, f)
except UnicodeDecodeError:
full_path = path.join(root, f.decode('latin1'))
# Looping on files contained
if path.splitext(full_path.lower())[1] == '.dwg':
""" listing DWG """
# add complete path of DWG file
li_dwg.append(full_path)
# looping on every DWG and adding the prj
for dwg in li_dwg:
# print(path.join(path.dirname(dwg), path.basename(dwg)[:-4]) + ".prj")
print(dwg)
copyfile(prj, path.join(path.dirname(dwg), path.basename(dwg)[:-4]) + ".prj")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment