AnsweredAssumed Answered

How to Add Field(s) to All shapefiles in a Folder

Question asked by bgeoca on Jul 9, 2012
Latest reply on Jul 9, 2012 by bgeoca

Can you please let me know how I can run an Arcpy script to add field(s) to all shapefiles inside a folder.I already tried this script but it did'nt I am encountering with Error
ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Table: Dataset Point.shp does not exist or is not supported Failed to execute (AddField).

import arcpy
import os

dirAd = "D:\GIS\Test"
fieldName1 = "ref_ID"
fieldPrecision = 9
fieldAlias = "refcode"
fieldName2 = "status"
fieldLength = 10

for files in os.listdir(dirAd):
    if files.endswith(".shp"):
       arcpy.AddField_management(files, fieldName1, "LONG", fieldPrecision, "", "",fieldAlias, "NULLABLE")
       arcpy.AddField_management(files, fieldName2, "TEXT", "", "", fieldLength)