<?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: Where to incorrporate IF and Else if file doesnt exist after os.walk? Python Question. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/where-to-incorrporate-if-and-else-if-file-doesnt/m-p/233399#M18111</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; import os
&amp;gt;&amp;gt;&amp;gt; mypath = r"Some\path"
&amp;gt;&amp;gt;&amp;gt; if os.path.exists(mypath):
&amp;nbsp; print 'do stuff'&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit:&lt;/P&gt;&lt;P&gt;Here is a better example:&lt;/P&gt;&lt;P&gt;Consider you have a file structure like below&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/190110_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;now if myfile points to the proper directory you would do the following&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for root, subfolders, files in os.walk(myfile):
&amp;nbsp; if os.path.exists(os.path.join(root,'New Text Document1.txt')):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'yes'&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 11:48:33 GMT</pubDate>
    <dc:creator>WesMiller</dc:creator>
    <dc:date>2021-12-11T11:48:33Z</dc:date>
    <item>
      <title>Where to incorrporate IF and Else if file doesnt exist after os.walk? Python Question.</title>
      <link>https://community.esri.com/t5/python-questions/where-to-incorrporate-if-and-else-if-file-doesnt/m-p/233395#M18107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #222426; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; text-align: left; background-color: rgba(248, 248, 248, 0.589844);"&gt;I am extremely new to python so any help would be greatly appreciated. How would you skip the arcpy.Merge and arcpy.Clip if 'AAA010.shp' does not exist in the directory that os.walk is going through. I will have more code after the last line in this snippet. Currently, the script just skips completely over the 'AAA010.shp' even though it exists. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #222426; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; text-align: left; background-color: rgba(248, 248, 248, 0.589844);"&gt;&lt;CODE style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif;"&gt;&lt;SPAN class="kwd" style="color: #00008b;"&gt;import&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; os&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; fnmatch&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; arcpy&lt;BR /&gt;&lt;BR /&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;env&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;workspace&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;&amp;nbsp; r&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;’&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;C&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;\Users\sysadmin\desktop\datamanagement\MGCP&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;gdb&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;’&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;&lt;BR /&gt;&lt;BR /&gt;fcMerged &lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; &lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;‘&lt;/SPAN&gt;&lt;SPAN class="typ" style="color: #2b91af;"&gt;MergedFeatureClass&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;’&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;&lt;BR /&gt;&lt;BR /&gt;fcClipped &lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; &lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;‘&lt;/SPAN&gt;&lt;SPAN class="typ" style="color: #2b91af;"&gt;ClippedFeatureClass&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;’&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;&lt;BR /&gt;&lt;BR /&gt;fcToClip &lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; r&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;’&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;C&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;\Users\sysadmin\desktop\datamanagement\Country&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;shp&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;’&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;&lt;BR /&gt;&lt;BR /&gt;filesMatched &lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; list&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;()&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="kwd" style="color: #00008b;"&gt;for&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; root&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; subfolders&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; files &lt;/SPAN&gt;&lt;SPAN class="kwd" style="color: #00008b;"&gt;in&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; os&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;walk&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;r&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;’&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;C&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;\Users\sysadmin\desktop\datamanagement\MGCP_Raw&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;’):&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="kwd" style="color: #00008b;"&gt;for&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; f &lt;/SPAN&gt;&lt;SPAN class="kwd" style="color: #00008b;"&gt;in&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; fnmatch&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;filer&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;files&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; &lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;‘&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;AAA010&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;shp&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;’):&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;&lt;BR /&gt;&amp;nbsp; filesMatched&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;append&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;os&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;path&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;join&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;root&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;f&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="kwd" style="color: #00008b;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; &lt;/SPAN&gt;&lt;SPAN class="str" style="color: maroon;"&gt;'AAA010.shp'&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; &lt;/SPAN&gt;&lt;SPAN class="kwd" style="color: #00008b;"&gt;in&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; filesMatched&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; arcpy&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ" style="color: #2b91af;"&gt;Merge_management&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; &lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;filesMatched&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; fcMerged&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; arcpy&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="typ" style="color: #2b91af;"&gt;Clip_analysis&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; &lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;fcMerged&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; fcToClip&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; &lt;/SPAN&gt;&lt;SPAN class="typ" style="color: #2b91af;"&gt;Extraction_Mine&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="kwd" style="color: #00008b;"&gt;else&lt;/SPAN&gt;&lt;SPAN class="pun" style="color: black;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="pln" style="color: black;"&gt; &lt;/SPAN&gt;&lt;SPAN class="kwd" style="color: #00008b;"&gt;pass&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Mar 2016 00:09:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-to-incorrporate-if-and-else-if-file-doesnt/m-p/233395#M18107</guid>
      <dc:creator>BrianButtaccio</dc:creator>
      <dc:date>2016-03-07T00:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Where to incorrporate IF and Else if file doesnt exist after os.walk? Python Question.</title>
      <link>https://community.esri.com/t5/python-questions/where-to-incorrporate-if-and-else-if-file-doesnt/m-p/233396#M18108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;brian, looks like geonet may have hiccup' don you question and duplicated it multiple times.&amp;nbsp; I would delete this one and a few of the other dupes so you only have one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;that has happened to me before (typically when my connection was flaky for a few minutes)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Mar 2016 00:16:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-to-incorrporate-if-and-else-if-file-doesnt/m-p/233396#M18108</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2016-03-07T00:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: Where to incorrporate IF and Else if file doesnt exist after os.walk? Python Question.</title>
      <link>https://community.esri.com/t5/python-questions/where-to-incorrporate-if-and-else-if-file-doesnt/m-p/233397#M18109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should also mention that this question was asked in &lt;A href="http://gis.stackexchange.com/questions/183162/how-to-code-to-skip-a-shapefile-if-it-doesnt-exist"&gt;gis.stackexchange&lt;/A&gt;​ (&lt;A href="http://gis.stackexchange.com/questions/183363/where-to-incorrporate-if-and-else-if-file-doesnt-exist-after-os-walk"&gt;twice&lt;/A&gt;, in fact), but was deemed unclear.&amp;nbsp; It would probably help if you provide more information, including the version of ArcGIS in use, the contents of the directories, and, after adding a lot more diagnostics, the output of the script with those diagnostics.&amp;nbsp; It's very difficult to help based on the information provided.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- V&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Mar 2016 01:04:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-to-incorrporate-if-and-else-if-file-doesnt/m-p/233397#M18109</guid>
      <dc:creator>VinceAngelo</dc:creator>
      <dc:date>2016-03-07T01:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: Where to incorrporate IF and Else if file doesnt exist after os.walk? Python Question.</title>
      <link>https://community.esri.com/t5/python-questions/where-to-incorrporate-if-and-else-if-file-doesnt/m-p/233398#M18110</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I deleted the multiple entries....thought spammy was back&lt;/P&gt;&lt;P&gt;PS&amp;nbsp; please format your&amp;nbsp; code&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migration-blogpost/55181"&gt;Code Formatting... the basics++&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Mar 2016 01:39:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-to-incorrporate-if-and-else-if-file-doesnt/m-p/233398#M18110</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-07T01:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: Where to incorrporate IF and Else if file doesnt exist after os.walk? Python Question.</title>
      <link>https://community.esri.com/t5/python-questions/where-to-incorrporate-if-and-else-if-file-doesnt/m-p/233399#M18111</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; import os
&amp;gt;&amp;gt;&amp;gt; mypath = r"Some\path"
&amp;gt;&amp;gt;&amp;gt; if os.path.exists(mypath):
&amp;nbsp; print 'do stuff'&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit:&lt;/P&gt;&lt;P&gt;Here is a better example:&lt;/P&gt;&lt;P&gt;Consider you have a file structure like below&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/190110_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;now if myfile points to the proper directory you would do the following&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for root, subfolders, files in os.walk(myfile):
&amp;nbsp; if os.path.exists(os.path.join(root,'New Text Document1.txt')):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'yes'&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:48:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-to-incorrporate-if-and-else-if-file-doesnt/m-p/233399#M18111</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2021-12-11T11:48:33Z</dc:date>
    </item>
  </channel>
</rss>

