<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Check existence of linked file for each record in table in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237961#M18497</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for the suggestions. I've built upon one, creating a standalone script that I've added to a custom toolbox. The body of the script is included below. This script will run and complete with no errors, but it won't produce the result I'm going for. The field "PhotoExists" still only contain null values. Any thoughts? And thanks again!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os

featureClass = arcpy.GetParameterAsText(0)

photo_field = "PhotoHotlink"
results_field = "PhotoExists"
curs = arcpy.UpdateCursor(featureClass, results_field)
row = curs.next()

for row in curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; photo_path = row.getValue(photo_field)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.exists(photo_path):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(results_field, "Y")
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(results_field, "N")

&amp;nbsp;&amp;nbsp;&amp;nbsp; curs.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = curs.next()


del curs, row
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 11:58:59 GMT</pubDate>
    <dc:creator>johnodonnell</dc:creator>
    <dc:date>2021-12-11T11:58:59Z</dc:date>
    <item>
      <title>Check existence of linked file for each record in table</title>
      <link>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237958#M18494</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;We have a feature class consisting of manholes. Each manhole has a corresponding photo. All the photos reside on the server. The photo file names equate to the manholes' unique ID number. There is a field in the feature class that is calculated to the file path to each manhole's photo. I need a bit of code that I can use in Field Calculator to check if there is indeed a photo at the end of each path. Any ideas?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jul 2012 17:41:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237958#M18494</guid>
      <dc:creator>johnodonnell</dc:creator>
      <dc:date>2012-07-31T17:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Check existence of linked file for each record in table</title>
      <link>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237959#M18495</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure about field calculator, but cursors will work well for this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;photo_field = "your_path_field" curs = arcpy.SearchCursor(fc,"","",photo_field) for row in curs: &amp;nbsp;&amp;nbsp;&amp;nbsp; photo_path = row.getValue(photo_field) &amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.exists(photo_path): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "%s exists" % os.path.basename(photo_path)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; else: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "%s not found" % os.path.basename(photo_path) &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Alternatively you can use an update cursor and fill a field with Exists Y/N during the check.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jul 2012 18:23:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237959#M18495</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-07-31T18:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: Check existence of linked file for each record in table</title>
      <link>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237960#M18496</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This can be done a different way and still be pretty easy.&amp;nbsp; If your images are stored in the same folder or directory then this won't be that bad.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can use the command prompt to list all files in a directory using the DIR command and export that to a text file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ex.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;DIR c:\ /B &amp;gt; c:\test.txt&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, test.txt has a list of all files in the directory c:\.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Open test.txt in Excel, remove your file types at the end (can be done using a simple find/replace).&amp;nbsp; Give the column a title like MANHOLE_ID and save the table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Create a short integer field in your Manhole table called something like IMG_EXIST.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can then open the table you created in Excel in ArcGIS, export it to have an OID, then join it to your Manhole's table.&amp;nbsp; Base the join off of the MANHOLE_ID field and keep all records.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Once joined, only matching values with have a MANHOLE_ID value in both the Manhole and Imported table will not have NULL values in the MANHOLE_ID field.&amp;nbsp; Use the field calculator to populate the IMG_EXIST field to denote if an image exists.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;dim x&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if IsNull( [MANHOLE_ID] ) then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;x = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;else&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;x = 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end if&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;IMG_EXIST = x&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All values of 0 will show manholes without an image, and manholes with 1 do have an image.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can save the scripts and use them to update the field as you get more images in the future.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not the python solution but hope it helps.&amp;nbsp; We do this same approach to populate fields for our websites which let a user know if attachments or additional documents exist for properties, etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Chris B.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jul 2012 18:40:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237960#M18496</guid>
      <dc:creator>ChristopherBlinn1</dc:creator>
      <dc:date>2012-07-31T18:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: Check existence of linked file for each record in table</title>
      <link>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237961#M18497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for the suggestions. I've built upon one, creating a standalone script that I've added to a custom toolbox. The body of the script is included below. This script will run and complete with no errors, but it won't produce the result I'm going for. The field "PhotoExists" still only contain null values. Any thoughts? And thanks again!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os

featureClass = arcpy.GetParameterAsText(0)

photo_field = "PhotoHotlink"
results_field = "PhotoExists"
curs = arcpy.UpdateCursor(featureClass, results_field)
row = curs.next()

for row in curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; photo_path = row.getValue(photo_field)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.exists(photo_path):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(results_field, "Y")
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(results_field, "N")

&amp;nbsp;&amp;nbsp;&amp;nbsp; curs.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = curs.next()


del curs, row
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:58:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237961#M18497</guid>
      <dc:creator>johnodonnell</dc:creator>
      <dc:date>2021-12-11T11:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Check existence of linked file for each record in table</title>
      <link>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237962#M18498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;your syntax for the cursor is a little off. The first parameter is the input which is correct, but the second parameter is the where clause which you have populated with your field variable. Also, you don't need to add the next row commands. You want it to look like this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os

featureClass = arcpy.GetParameterAsText(0)

photo_field = "PhotoHotlink"
results_field = "PhotoExists"
&lt;STRONG&gt;curs = arcpy.UpdateCursor(featureClass, "", "", [photo_field, results_field])&lt;/STRONG&gt;
#row = curs.next()

for row in curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; photo_path = row.getValue(photo_field)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.exists(photo_path):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(results_field, "Y")
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(results_field, "N")

&amp;nbsp;&amp;nbsp;&amp;nbsp; curs.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; #row = curs.next()


del curs, row&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Actually, you need to include both your reading and writing fields.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:59:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237962#M18498</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T11:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: Check existence of linked file for each record in table</title>
      <link>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237963#M18499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the fast response! I made the corrections you suggested and got the following error/message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Executing: Script P:\xxxxxxxxx&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Start Time: Wed Aug 01 13:28:06 2012&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Running script Script...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "P:\2012_Projects\12004_Chatt_ST_DBCC\Toolboxes\PhotoExists2.py", line 13, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.exists(photo_path):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Python27\ArcGIS10.1\Lib\genericpath.py", line 18, in exists&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.stat(path)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TypeError: coercing to Unicode: need string or buffer, NoneType found&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Script).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed at Wed Aug 01 13:28:31 2012 (Elapsed Time: 25.00 seconds)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any idea what's wrong?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Aug 2012 16:34:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237963#M18499</guid>
      <dc:creator>johnodonnell</dc:creator>
      <dc:date>2012-08-01T16:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Check existence of linked file for each record in table</title>
      <link>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237964#M18500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Never mind! It works great! Thanks so much for your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Aug 2012 16:50:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-existence-of-linked-file-for-each-record-in/m-p/237964#M18500</guid>
      <dc:creator>johnodonnell</dc:creator>
      <dc:date>2012-08-01T16:50:17Z</dc:date>
    </item>
  </channel>
</rss>

