<?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: Python directory question in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208113#M16066</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/347784"&gt;Marco Pretorius&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The quickest solution would be to replace all backward slashes in your directory paths to forward ones.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;'C:\users\user\Test2\pictures.gdb\pictures__ATTACH'&lt;/SPAN&gt; should become &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;'C:/users/user/Test2/pictures.gdb/pictures__ATTACH'&lt;/SPAN&gt;, etcetera.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And then save and run the script again &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does this solve your issue?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Egge-Jan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 14 Jun 2019 14:55:17 GMT</pubDate>
    <dc:creator>Egge-Jan_Pollé</dc:creator>
    <dc:date>2019-06-14T14:55:17Z</dc:date>
    <item>
      <title>Python directory question</title>
      <link>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208112#M16065</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;import arcpy&lt;BR /&gt;from arcpy import da&lt;BR /&gt;import os&lt;/P&gt;&lt;P&gt;attachTable = 'C:\users\user\Test2\pictures.gdb\pictures__ATTACH' # Table in GDB holding attatchments&lt;BR /&gt;origTable = 'C:\Users\user\Test2\pictures.gdb\pictures' # Layer in GDB holding features to which attatchments belong&lt;BR /&gt;nameField = 'Name' # Field where you want to save the photos&lt;BR /&gt;fileLocation = 'C:\Users\user\pictures\pics' # folder where you want to save the photos&lt;/P&gt;&lt;P&gt;# creates a cursor to search through the attachment tables; specify yu only wish to search those three fields&lt;BR /&gt;attachCursor = arcpy.da.SearchCursor(attachTable, ['DATA', 'ATT_NAME', 'REL_GLOBALID'])&lt;/P&gt;&lt;P&gt;# Begin searching the table and storing the actual images, movies, etc.&lt;BR /&gt;for attRow in attachCursor:&lt;BR /&gt; binaryRep = attRow[0]&lt;BR /&gt; filename = attRow[1]&lt;BR /&gt; relID = attRow[2]&lt;/P&gt;&lt;P&gt;# creates a cursor to sort the features; essentially to find a match fro the relID above&lt;BR /&gt; originCursor = arcpy.da.SearchCursor(origTable, ['GLOBALID', nameField])&lt;BR /&gt; for origRow in originCursor:&lt;BR /&gt; origID = origRow[0]&lt;BR /&gt; origName = origRow[1]&lt;BR /&gt; if origID == relID:&lt;BR /&gt; break&lt;/P&gt;&lt;P&gt;# Saves a file in the specified location tht contains the name chosen by the user for the attachment&lt;BR /&gt; open(fileLocation + os.sep + origName + ".jpg", 'wb').write(binaryRep.tobytes())&lt;/P&gt;&lt;P&gt;# deletes search cursor&lt;BR /&gt; del originCursor&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;ERROR&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; File "C:/Users/mpretorius/Desktop/att.py", line 28, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt; open(fileLocation + os.sep + origName + ".jpg", 'wb').write(binaryRep.tobytes())&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;IOError: [Errno 2] No such file or directory: u'C:\\Users\\user\\pictures\\pics\\HGC-2.jpg'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;Can't seem to figure out what is wrong in this script. Any help appreciated!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jun 2019 14:34:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208112#M16065</guid>
      <dc:creator>MarcoPretorius1</dc:creator>
      <dc:date>2019-06-14T14:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: Python directory question</title>
      <link>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208113#M16066</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/347784"&gt;Marco Pretorius&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The quickest solution would be to replace all backward slashes in your directory paths to forward ones.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;'C:\users\user\Test2\pictures.gdb\pictures__ATTACH'&lt;/SPAN&gt; should become &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;'C:/users/user/Test2/pictures.gdb/pictures__ATTACH'&lt;/SPAN&gt;, etcetera.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And then save and run the script again &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does this solve your issue?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Egge-Jan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jun 2019 14:55:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208113#M16066</guid>
      <dc:creator>Egge-Jan_Pollé</dc:creator>
      <dc:date>2019-06-14T14:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Python directory question</title>
      <link>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208114#M16067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Getting this error&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt; File "C:/Users/user/Desktop/att.py", line 28, in &amp;lt;module&amp;gt;&lt;BR /&gt; open(fileLocation + os.sep + origName + ".jpg", 'wb').write(binaryRep.tobytes())&lt;BR /&gt;IOError: [Errno 2] No such file or directory: u'C:/Users/user/pictures/pics/\\HGC-2.jpg'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any further suggestions?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jun 2019 15:13:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208114#M16067</guid>
      <dc:creator>MarcoPretorius1</dc:creator>
      <dc:date>2019-06-14T15:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Python directory question</title>
      <link>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208115#M16068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The Python open command will not be able to create a directory if it doesn't exist, just a file, so make sure all of the directories in the path exist prior to running that command.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jun 2019 15:48:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208115#M16068</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-06-14T15:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: Python directory question</title>
      <link>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208116#M16069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;for line numbers to facilitate references to script lines see&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting"&gt;/blogs/dan_patterson/2016/08/14/script-formatting&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jun 2019 16:24:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208116#M16069</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-06-14T16:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python directory question</title>
      <link>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208117#M16070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The issue might be caused by the two backslashes in the filename: C:/Users/user/pictures/pics/&lt;STRONG&gt;\\HGC-2.jpg&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;You should try to find out where these come from.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Jun 2019 16:48:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208117#M16070</guid>
      <dc:creator>Egge-Jan_Pollé</dc:creator>
      <dc:date>2019-06-14T16:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: Python directory question</title>
      <link>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208118#M16071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should have gotten failures way before you did.&lt;/P&gt;&lt;P&gt;You need to raw encode your paths little 'r'&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;p &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'C:\users\user\Test2\pictures.gdb\pictures__ATTACH'&lt;/SPAN&gt;
  File &lt;SPAN class="string token"&gt;"&amp;lt;ipython-input-2-3d412528dd89&amp;gt;"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; line &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
    p &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'C:\users\user\Test2\pictures.gdb\pictures__ATTACH'&lt;/SPAN&gt;
       &lt;SPAN class="operator token"&gt;^&lt;/SPAN&gt;
SyntaxError&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;unicode error&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'unicodeescape'&lt;/SPAN&gt; codec can't decode bytes &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; position &lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;3&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; truncated \uXXXX escape


p &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'C:\users\user\Test2\pictures.gdb\pictures__ATTACH'&lt;/SPAN&gt;  &lt;SPAN class="comment token"&gt;# --- raw encoded&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# use all forward slashes&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:17:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-directory-question/m-p/208118#M16071</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T10:17:01Z</dc:date>
    </item>
  </channel>
</rss>

