-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathListallPrjExtFields_subdir.py
36 lines (33 loc) · 1.48 KB
/
ListallPrjExtFields_subdir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#list projection name, extent and field of all shp files under a directory
import arcpy,csv,os
mydir = #drag and drop a folder from ArcCatalogue
file = r'list_all.csv'
outfile = mydir +'\\'+ file
# listing all files in subdirectoires
# ---below code borrowed from https://goo.gl/g6Mihd
def list_files(dir):
r = []
subdirs = [x[0] for x in os.walk(dir)]
for subdir in subdirs:
files = os.walk(subdir).next()[2]
if (len(files) > 0):
for file in files:
r.append(subdir+ '\\' + file)
return r
# #--loop through all files ending in .shp, list projection names etc in a new row and save as csv
with open(outfile,'w+b') as f:
w = csv.writer(f)
for file in list_files(mydir):
if file.endswith(".shp"):
fields = arcpy.ListFields(file)
field_names = [field.name for field in fields]
desc = arcpy.Describe(file)
sr = ([desc.spatialReference.name])
#ext= ([desc.extent])
aRow = ([mydir])
aRow.extend([file])
aRow.extend(sr)
#aRow.extend(ext)
aRow.extend(field_names)
w.writerow(aRow)
f.close