<?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: Script to save attachments overwriting duplicates in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/script-to-save-attachments-overwriting-duplicates/m-p/1553234#M73101</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/822201"&gt;@SamBelisleLID1990&lt;/a&gt;,&amp;nbsp;take a look at the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/export-attachments.htm" target="_self"&gt;Export Attachments&lt;/A&gt; tool, which is new at ArcGIS Pro version 3.3.&amp;nbsp; This tool provides options on how to handle the name format of the exported attachments:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JakeSkinner_0-1730206441629.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118327i37BAA5E5B29D13C4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JakeSkinner_0-1730206441629.png" alt="JakeSkinner_0-1730206441629.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Oct 2024 12:54:15 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2024-10-29T12:54:15Z</dc:date>
    <item>
      <title>Script to save attachments overwriting duplicates</title>
      <link>https://community.esri.com/t5/python-questions/script-to-save-attachments-overwriting-duplicates/m-p/1553057#M73100</link>
      <description>&lt;P&gt;I have a script I am running in ArcGIS Pro that downloads a file geodatabase of a feature class and saves attachments as JPEGs from the FGDB. The original feature class often has multiple attachments for each record, and sometimes multiple records for each 'site.' I need all of these attachments to save separately.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My script currently overwrites the previous attachment with the latest one. I need it to save a new attachment with "--2" or "--3" at the end of each subsequent attachment. So a site with one recrod that has 2 attachments would have two JPEGs saved: "SiteNumber.jpg" and "SiteNumber--2.jpg".&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 21:48:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-save-attachments-overwriting-duplicates/m-p/1553057#M73100</guid>
      <dc:creator>SamBelisleLID1990</dc:creator>
      <dc:date>2024-10-28T21:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Script to save attachments overwriting duplicates</title>
      <link>https://community.esri.com/t5/python-questions/script-to-save-attachments-overwriting-duplicates/m-p/1553234#M73101</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/822201"&gt;@SamBelisleLID1990&lt;/a&gt;,&amp;nbsp;take a look at the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/export-attachments.htm" target="_self"&gt;Export Attachments&lt;/A&gt; tool, which is new at ArcGIS Pro version 3.3.&amp;nbsp; This tool provides options on how to handle the name format of the exported attachments:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JakeSkinner_0-1730206441629.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118327i37BAA5E5B29D13C4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JakeSkinner_0-1730206441629.png" alt="JakeSkinner_0-1730206441629.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2024 12:54:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-save-attachments-overwriting-duplicates/m-p/1553234#M73101</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-10-29T12:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Script to save attachments overwriting duplicates</title>
      <link>https://community.esri.com/t5/python-questions/script-to-save-attachments-overwriting-duplicates/m-p/1553314#M73102</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;,&amp;nbsp;I am able to name the files according to the field values. The problem is that I can't get it to recognize the duplicates. The first attachment will download with the correct file name, then the second attachment will overwrite the first attachment with the same file name, meaning the data is not captured instead of saving as a new file.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2024 15:11:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-save-attachments-overwriting-duplicates/m-p/1553314#M73102</guid>
      <dc:creator>SamBelisleLID1990</dc:creator>
      <dc:date>2024-10-29T15:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: Script to save attachments overwriting duplicates</title>
      <link>https://community.esri.com/t5/python-questions/script-to-save-attachments-overwriting-duplicates/m-p/1553573#M73112</link>
      <description>&lt;P&gt;You can loop through and check the existence of a file in the output location, and update the name using an approach like the following (untested and not properly indented):&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;filenum = 2&lt;BR /&gt;attachment = item[0]&lt;BR /&gt;filename = f'{item[3]}.jpg'&lt;BR /&gt;while os.path.exists(os.path.join(fileLocation, filename)): #check the output location&lt;BR /&gt;    arcpy.AddMessage(f'{filename} already exists, trying --{filenum}')&lt;BR /&gt;    filename = f'{item[3]}--{filenum}.jpg'&lt;BR /&gt;    filecount += 1&lt;BR /&gt;open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
    &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2024 21:40:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-save-attachments-overwriting-duplicates/m-p/1553573#M73112</guid>
      <dc:creator>GrantHerbert</dc:creator>
      <dc:date>2024-10-29T21:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: Script to save attachments overwriting duplicates</title>
      <link>https://community.esri.com/t5/python-questions/script-to-save-attachments-overwriting-duplicates/m-p/1553588#M73113</link>
      <description>&lt;P&gt;If you specify&amp;nbsp;&lt;STRONG&gt;Add Field Values as Suffix&lt;/STRONG&gt; it will handle duplicates by adding an _1, _2, etc.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JakeSkinner_2-1730240653065.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118411i4B2B4B5DEA2266EE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JakeSkinner_2-1730240653065.png" alt="JakeSkinner_2-1730240653065.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JakeSkinner_1-1730240612848.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/118410i8011AD60BF0A75C1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JakeSkinner_1-1730240612848.png" alt="JakeSkinner_1-1730240612848.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Oct 2024 22:24:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-save-attachments-overwriting-duplicates/m-p/1553588#M73113</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-10-29T22:24:18Z</dc:date>
    </item>
  </channel>
</rss>

