<?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: Cannot delete files in FGDB - Need Arcpy solution in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680704#M52754</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;With your cursors prior to this code, are you deleting the cursor objects after you are done with them?&amp;nbsp; Using a Python &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;with&lt;/SPAN&gt; statement will address locks, or most of them, but the cursor object still exists after the &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;with&lt;/SPAN&gt; statement executes and there could be file handles still open.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Esri's initial documentation of using &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;with&lt;/SPAN&gt; statements was very misleading, I submitted feedback and logged documentation defects to point out that using &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;with&lt;/SPAN&gt; doesn't guarantee all locks and file handles are released.&amp;nbsp; Esri finally updated the documentation with 10.5, &lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/10.5/analyze/arcpy-data-access/searchcursor-class.htm" title="http://desktop.arcgis.com/en/arcmap/10.5/analyze/arcpy-data-access/searchcursor-class.htm"&gt;SearchCursor—Help | ArcGIS Desktop&lt;/A&gt; :&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Search cursors can be iterated using a &lt;SPAN class=""&gt;for&lt;/SPAN&gt; loop. Search cursors also support &lt;SPAN class=""&gt;with&lt;/SPAN&gt; statements to reset iteration and aid in removal of locks. However, using a &lt;SPAN class=""&gt;del&lt;/SPAN&gt; statement to delete the object or wrapping the cursor in a function to have the cursor object go out of scope should be considered to guard against all locking cases.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 Jan 2019 14:48:44 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2019-01-03T14:48:44Z</dc:date>
    <item>
      <title>Cannot delete files in FGDB - Need Arcpy solution</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680703#M52753</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have created a script where at the end of it, I transfer records from and FGDB to a SDE database. I use the editor and believe I stop the operations correctly. At the end of this process, there are no longer any lock files in my FGDB. When I go to delete the entire FGDB, it gets hung up on .gdbtable and the deletion process will stop (and I assume if that got fixed, it would get hung up on .gdbindexes, .gdbtablx, or .spx).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried compacting the database and this does not work. I have tested that I can obtain a schema lock on one of the feature classes inside the FGDB and it says I can, I&amp;nbsp;&lt;EM&gt;think&lt;/EM&gt; this indicates that exclusive locks are not present. When I look in file explorer, there are no locks present. I really need an arcpy solution to this problem so the FGDB deletes successfully.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is my code, starting at the editor process. Before this piece of code, I&amp;nbsp;use search cursors on the FGDB with the with/as notation (so cursor locks should be deleted automatically).&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;#Instiantiate an editing object on the HbMonitoring database.&lt;/SPAN&gt;
editor &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Editor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;hb_db_con&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;try&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Updating Observers table with new observers..."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; editor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;startEditing&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;False&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;False&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; editor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;startOperation&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;#Create insert cursor to insert new observers into the Observers database table&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &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;InsertCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;obsvTable&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; obsvFields&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; obsvCursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; item &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; newObservers&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; obsvCursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;insertRow&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;item&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; editor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;stopOperation&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; editor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;stopEditing&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;except&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;#do stuff&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;try&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Copying data to Patches table..."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; editor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;startEditing&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;False&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;False&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; editor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;startOperation&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;#Create insert cursor to insert new rows into the Patches table&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &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;InsertCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;PatchesFC&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; icFields&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; iCursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Inserting patch row..."&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; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; item &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; patchInsert&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; iCursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;insertRow&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;item&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; editor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;stopOperation&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; editor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;stopEditing&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;except&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;#do stuff&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;try&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Copying data to Protective Cover table..."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; editor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;startEditing&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;False&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;False&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; editor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;startOperation&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;#Create insert cursor to insert new rows into the ProtectiveCover table&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &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;InsertCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;proCovFC&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; iPCFields&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; pcCursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; item &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; pcInsert&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pcCursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;insertRow&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;item&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; editor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;stopOperation&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; editor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;stopEditing&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;except&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;#do stuff&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;#Delete the scratch folder and scratch GDB&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;#If working with database from ArcMap interface&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"C:\Users"&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; scratchFolder&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Deleting scratch folder..."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; shutil&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;rmtree&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;scratchFolder&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Compact_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;scratchGDB&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Deleting scratch GDB..."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; shutil&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;rmtree&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;scratchGDB&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;/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;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;/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;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;/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;P&gt;&lt;/P&gt;&lt;P&gt;These are the files that are left after I attempt to delete the FGDB (ignore the "VLC media file" - it's just Windows assuming it knows what program to open .spx files in)&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="432516" alt="" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/432516_Capture.JPG" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:39:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680703#M52753</guid>
      <dc:creator>MKF62</dc:creator>
      <dc:date>2021-12-12T04:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot delete files in FGDB - Need Arcpy solution</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680704#M52754</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;With your cursors prior to this code, are you deleting the cursor objects after you are done with them?&amp;nbsp; Using a Python &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;with&lt;/SPAN&gt; statement will address locks, or most of them, but the cursor object still exists after the &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;with&lt;/SPAN&gt; statement executes and there could be file handles still open.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Esri's initial documentation of using &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;with&lt;/SPAN&gt; statements was very misleading, I submitted feedback and logged documentation defects to point out that using &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;with&lt;/SPAN&gt; doesn't guarantee all locks and file handles are released.&amp;nbsp; Esri finally updated the documentation with 10.5, &lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/10.5/analyze/arcpy-data-access/searchcursor-class.htm" title="http://desktop.arcgis.com/en/arcmap/10.5/analyze/arcpy-data-access/searchcursor-class.htm"&gt;SearchCursor—Help | ArcGIS Desktop&lt;/A&gt; :&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Search cursors can be iterated using a &lt;SPAN class=""&gt;for&lt;/SPAN&gt; loop. Search cursors also support &lt;SPAN class=""&gt;with&lt;/SPAN&gt; statements to reset iteration and aid in removal of locks. However, using a &lt;SPAN class=""&gt;del&lt;/SPAN&gt; statement to delete the object or wrapping the cursor in a function to have the cursor object go out of scope should be considered to guard against all locking cases.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2019 14:48:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680704#M52754</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-01-03T14:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot delete files in FGDB - Need Arcpy solution</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680705#M52755</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, I will give that a shot because I am not using "del" statements right now after cursors. I also discovered through debug that some locks are actually persisting but disappear once the script completes with an error (which makes perfect sense now that I think about it...).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2019 14:54:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680705#M52755</guid>
      <dc:creator>MKF62</dc:creator>
      <dc:date>2019-01-03T14:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot delete files in FGDB - Need Arcpy solution</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680706#M52756</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Alright - so close to working. Now I am left with two files right before the script errors out and it's getting hung up on deleting the "timestamps" file saying something else is accessing it. Right before the script errors out I have a _gdb lock file, it disappears once I close the console window where the script is running (which effectively stops the script).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2019 15:07:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680706#M52756</guid>
      <dc:creator>MKF62</dc:creator>
      <dc:date>2019-01-03T15:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot delete files in FGDB - Need Arcpy solution</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680707#M52757</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class=""&gt;#Delete the scratch folder and scratch GDB&lt;/SPAN&gt;
&lt;SPAN class=""&gt;#If working with database from ArcMap interface&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;What if you run the code outside of ArcMap entirely?&amp;nbsp; I ask because I have seen ArcMap/ArcCatalog keep handles on the timestamps files in the GDBs, so regardless of what you are doing with ArcPy those files can't be deleted until ArcMap/ArcCatalog releases them.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:39:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680707#M52757</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-12T04:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot delete files in FGDB - Need Arcpy solution</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680708#M52758</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try deleting your editor object as well (using del) and rather than using rmtree to delete your FGDB, try using the arcpy.Delete_management geoprocessing tool.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Jan 2019 20:53:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680708#M52758</guid>
      <dc:creator>JamesMacKay3</dc:creator>
      <dc:date>2019-01-04T20:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot delete files in FGDB - Need Arcpy solution</title>
      <link>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680709#M52759</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Great point, especially about using ArcGIS's own tool to remove the GDB.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Jan 2019 20:55:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cannot-delete-files-in-fgdb-need-arcpy-solution/m-p/680709#M52759</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-01-04T20:55:53Z</dc:date>
    </item>
  </channel>
</rss>

