<?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 for renaming file paths in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755537#M58278</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you are tripping over double quotes...&lt;/P&gt;&lt;P&gt;(r"\\","/") blah blah&lt;/P&gt;&lt;P&gt;try (r'\\', '/') blah blah&lt;/P&gt;&lt;P&gt;a couple of single quotes might go a long way&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 28 Apr 2017 14:22:01 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2017-04-28T14:22:01Z</dc:date>
    <item>
      <title>Python for renaming file paths</title>
      <link>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755532#M58273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am fairly new to python and am having issues renaming file paths within a table. I need to replace all of my \ for / within a field. \ is an escape so it is not working. Here is a brief snippet of my code:&lt;/P&gt;&lt;P&gt;arcpy.CalculateField_management(in_table="Assess", field="IMAGELINK", expression="""!IMAGELINK!.replace(r"\","/")""", expression_type="PYTHON_9.3", code_block="")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know there are easy ways to do this with VB and with field calculator but I am trying to automatic a much bigger table update.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edit:&amp;nbsp;&lt;SPAN style="color: #242729; background-color: #ffffff;"&gt;I've tried using \ \ instead and still had no luck.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #242729; background-color: #ffffff;"&gt;edit 2: This is ultimately what worked for me, thank you Joshua&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;expression&lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.498039); border: 0px; font-weight: inherit;"&gt;=&lt;/SPAN&gt;r&lt;SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;"&gt;"""!IMAGELINK!.replace("\\","/")"""&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any advice is much appreciated! Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:03:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755532#M58273</guid>
      <dc:creator>KelseyQuinlan</dc:creator>
      <dc:date>2021-12-12T08:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: Python for renaming file paths</title>
      <link>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755533#M58274</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What about escaping the escape character &lt;SPAN style="font-family: courier new,courier,monospace;"&gt;"\\"&lt;/SPAN&gt; .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Apr 2017 13:57:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755533#M58274</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2017-04-28T13:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: Python for renaming file paths</title>
      <link>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755534#M58275</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, unfortunately " \ \" still bombs the script. not quite sure what I am missing here, I thought that would be the easy solution too.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the reply!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Apr 2017 14:12:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755534#M58275</guid>
      <dc:creator>KelseyQuinlan</dc:creator>
      <dc:date>2017-04-28T14:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python for renaming file paths</title>
      <link>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755535#M58276</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What do you mean by "bomb?"&amp;nbsp; Providing the specific error message is helpful for those trying to help resolve your issue.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Apr 2017 14:15:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755535#M58276</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2017-04-28T14:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Python for renaming file paths</title>
      <link>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755536#M58277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure thing,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;New Script:&amp;nbsp;arcpy.CalculateField_management(in_table="AssessVP", field="IMAGELINK", expression="""!IMAGELINK!.replace(r"\\","/")""", expression_type="PYTHON_9.3", code_block="")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Error Message: Runtime error Traceback (most recent call last): File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt; File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 3457, in CalculateField raise e ExecuteError: ERROR 000539: SyntaxError: EOL while scanning string literal (&amp;lt;expression&amp;gt;, line 1) Failed to execute (CalculateField).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Apr 2017 14:18:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755536#M58277</guid>
      <dc:creator>KelseyQuinlan</dc:creator>
      <dc:date>2017-04-28T14:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python for renaming file paths</title>
      <link>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755537#M58278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you are tripping over double quotes...&lt;/P&gt;&lt;P&gt;(r"\\","/") blah blah&lt;/P&gt;&lt;P&gt;try (r'\\', '/') blah blah&lt;/P&gt;&lt;P&gt;a couple of single quotes might go a long way&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Apr 2017 14:22:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755537#M58278</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-04-28T14:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Python for renaming file paths</title>
      <link>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755538#M58279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It isn't uncommon to run into issues with backslashes in strings within strings when passing arguments to geoprocessing tools.&amp;nbsp; I believe either of the following will work:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;expression&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;r&lt;SPAN class="string token"&gt;"""!IMAGELINK!.replace("\\","/")"""&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# or&lt;/SPAN&gt;
expression&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"""!IMAGELINK!.replace("\\\\","/")"""&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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:03:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755538#M58279</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-12T08:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: Python for renaming file paths</title>
      <link>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755539#M58280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried using &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-data-access/updatecursor-class.htm"&gt;arcpy.da.UpdateCursor&lt;/A&gt; rather than the Calculate Field tool? That's how I would accomplish this task.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Apr 2017 15:45:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755539#M58280</guid>
      <dc:creator>JeffJacobson</dc:creator>
      <dc:date>2017-04-28T15:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: Python for renaming file paths</title>
      <link>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755540#M58281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you! That did the trick&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I really appreciate everybody's input!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Apr 2017 15:47:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755540#M58281</guid>
      <dc:creator>KelseyQuinlan</dc:creator>
      <dc:date>2017-04-28T15:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: Python for renaming file paths</title>
      <link>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755541#M58282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's how I would do it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This avoids&amp;nbsp;having to handle the complex string literals by using os.normpath (which converts all delimiters [including duplicated ones] to \ on Windows), os.sep (which allows you to get at \ without having to specify it with a string literal). Lastly, using an arcpy.da &amp;nbsp;UpdateCursor instead of Calculate Field avoids the complexity of a code block (and, very fastly [you said this was a big table]).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; os
&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;UpdateCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Assess"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"IMAGELINK"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; rows&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; rows&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;normpath&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;replace&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;sep&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"/"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;updateRow&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;row&lt;SPAN class="punctuation token"&gt;)&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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:03:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-for-renaming-file-paths/m-p/755541#M58282</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-12T08:03:30Z</dc:date>
    </item>
  </channel>
</rss>

