AnsweredAssumed Answered

Count Rows being processed with INSERT Cursor

Question asked by jay.kapalczynski on Oct 7, 2016
Latest reply on Oct 12, 2016 by CDow-esristaff

I have a script that is looping through many txt files and adding them to a feature class.  I want to tally the total number of records added.  

 

I am trying to use a RecordCounter Variable to count the records....It DOES work to some degree...it count the first txt file that is being processed but if I process 7 files it only gives me the number from the first txt file.

 

Any thoughts?

 

# .... SNIP

else: # SEEING THERE ARE NO DUPS PROCEED WITH PROCESSING
    print "They are no dups so processing is continuing"
    #Read through each line of the csv, but skip the first row because it is the header
    #The count variable skips of the first row
    count = 0
    RecordCounter = 0
    for ln in open (textFile, 'r').readlines(): 
        if count > 0:
            #Each line in the csv is a string, so turn it into a list so you can reference each column
            lineSplit = ln.split(",")

            #Use index positions to get the right column from the csv
            #Make sure the data is the correct type (i.e. X and Y need to be numbers, not strings)
            CollarSeri = long(lineSplit[0])
            Year = str(lineSplit[1])
            Julianday = str(lineSplit[2])                              

            #Insert the values from csv into feature class
            #The order of the fields here, matches the order of the fields in line 4
            cursor.insertRow ([CollarSeri, Year, Julianday, Hour, Minute, Activity, Temperature, Latitude, Longitude, HDOP, NumSats, FixTime, Date, _2D_3D, BearID, getTime3, getDateTime, FileName, shapeVal])
               
         RecordCounter = RecordCounter + 1

         count += 1
                                  
     del cursor
    
     print RecordCounter

# .... SNIP

Outcomes