I want to convert my .txt files to shapefile. I want the system to be able to move to the next .txt file in the folder, other than me inputting one after the other. This is what I have done but I have to input the files one after the other which takes a lot of time
import arcpy
newfcName ="532724.shp"
outpath = r"C:/FLOOD/IKEJA AND KOSOFE"
Declaration
arcpy.env.overwriteOutput=True
arcpy.env.workspace= outpath
Create new Shapefile and add FIELDS
newfc = arcpy.CreateFeatureclass_management(outpath, newfcName, "Point")
arcpy.AddField_management(newfc, "X", "STRING", field_length = 50)
arcpy.AddField_management(newfc, "Y", "STRING", field_length = 50)
arcpy.AddField_management(newfc, "Z", "STRING", field_length = 50)
arcpy.AddField_management(newfc, "I", "FLOAT", field_length = 50)
Reference Cursors
cursor=arcpy.da.InsertCursor(newfc, [ "SHAPE@XY", "X", "Y", "Z", "I"])
Read File
a = open("C:/FLOOD/IKEJA AND KOSOFE/DEM/532724.txt","r")
inputF = a.readlines()
for line in inputF:
xCoordinate, yCoordinate, zValue, iValue = line.split(" ")
xy = (float(xCoordinate), float(yCoordinate))
newRow = (xy, str(xCoordinate), str(yCoordinate), str(zValue), float(iValue))
cursor.insertRow(newRow)
a.close()
infc = r"C:/FLOOD/IKEJA AND KOSOFE/532724.shp"
sr = arcpy.SpatialReference("Minna UTM Zone 31N")
arcpy.DefineProjection_management(infc, sr)