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?
<SPAN class="comment token"># .... SNIP</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># SEEING THERE ARE NO DUPS PROCEED WITH PROCESSING</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"They are no dups so processing is continuing"</SPAN>
<SPAN class="comment token">#Read through each line of the csv, but skip the first row because it is the header</SPAN>
<SPAN class="comment token">#The count variable skips of the first row</SPAN>
count <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
RecordCounter <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="keyword token">for</SPAN> ln <SPAN class="keyword token">in</SPAN> open <SPAN class="punctuation token">(</SPAN>textFile<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'r'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>readlines<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> count <SPAN class="operator token">></SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token">#Each line in the csv is a string, so turn it into a list so you can reference each column</SPAN>
lineSplit <SPAN class="operator token">=</SPAN> ln<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">","</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Use index positions to get the right column from the csv</SPAN>
<SPAN class="comment token">#Make sure the data is the correct type (i.e. X and Y need to be numbers, not strings)</SPAN>
CollarSeri <SPAN class="operator token">=</SPAN> long<SPAN class="punctuation token">(</SPAN>lineSplit<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
Year <SPAN class="operator token">=</SPAN> str<SPAN class="punctuation token">(</SPAN>lineSplit<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
Julianday <SPAN class="operator token">=</SPAN> str<SPAN class="punctuation token">(</SPAN>lineSplit<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Insert the values from csv into feature class</SPAN>
<SPAN class="comment token">#The order of the fields here, matches the order of the fields in line 4</SPAN>
cursor<SPAN class="punctuation token">.</SPAN>insertRow <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>CollarSeri<SPAN class="punctuation token">,</SPAN> Year<SPAN class="punctuation token">,</SPAN> Julianday<SPAN class="punctuation token">,</SPAN> Hour<SPAN class="punctuation token">,</SPAN> Minute<SPAN class="punctuation token">,</SPAN> Activity<SPAN class="punctuation token">,</SPAN> Temperature<SPAN class="punctuation token">,</SPAN> Latitude<SPAN class="punctuation token">,</SPAN> Longitude<SPAN class="punctuation token">,</SPAN> HDOP<SPAN class="punctuation token">,</SPAN> NumSats<SPAN class="punctuation token">,</SPAN> FixTime<SPAN class="punctuation token">,</SPAN> Date<SPAN class="punctuation token">,</SPAN> _2D_3D<SPAN class="punctuation token">,</SPAN> BearID<SPAN class="punctuation token">,</SPAN> getTime3<SPAN class="punctuation token">,</SPAN> getDateTime<SPAN class="punctuation token">,</SPAN> FileName<SPAN class="punctuation token">,</SPAN> shapeVal<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
RecordCounter <SPAN class="operator token">=</SPAN> RecordCounter <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN>
count <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="keyword token">del</SPAN> cursor
<SPAN class="keyword token">print</SPAN> RecordCounter
<SPAN class="comment token"># .... SNIP</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>