-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlistallfields2.py
More file actions
21 lines (18 loc) · 854 Bytes
/
listallfields2.py
File metadata and controls
21 lines (18 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import arcpy,csv,os
#mydir = r'C:\Users\william\Documents\MIMU\Data\Transport\\'
mydir = r'D:\20161212_Basic ArcGIS Training\Day1\Data\commondata\01_admin\\'
outfile = r'C:\temp\test3.txt'
#--loop through all files endin in .shp, list fields in a new row
with open(outfile,'w+') as f:
w = csv.writer(f)
for file in os.listdir(mydir):
if file.endswith(".shp"):
fields = arcpy.ListFields(mydir+file)
field_names = [field.name for field in fields]
#--write all field names to the output file
all_field_names = ([mydir])
file_name = ([file])// new lines added by knw
all_field_names.extend(file_name)// new lines added by knw
all_field_names.extend(field_names)// new lines added by knw
w.writerow(all_field_names)
f.close