<?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: ListBrokenDataSources not working in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77016#M6239</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;A new feature dataset or a new GDB?&amp;nbsp; Feature classes with the same name can't exist in two different feature datasets in the same GDB.&amp;nbsp; I.e., all feature classes in a GDB must have a unique name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 10 Sep 2012 12:59:06 GMT</pubDate>
    <dc:creator>JeffBarrette</dc:creator>
    <dc:date>2012-09-10T12:59:06Z</dc:date>
    <item>
      <title>ListBrokenDataSources not working</title>
      <link>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77013#M6236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In my SHP to GDB toolbox, I create a list of layers in MXD, then I check for those not broken I move them. Despite using ListBrokenDataSources I have errors like this: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;type 'exceptions.WindowsError'&amp;gt;: [Error 3] Impossibile trovare il percorso specificato: u'J:\\20120208_Backup_disco_E\\Archivio\\ATLArete\\Shape Atlarete 1-1-2008\\miste.shp'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm desperate at this point, any help????&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Following my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Create a list of SHP in mxd 
list = []
df_list = arcpy.mapping.ListDataFrames (mxd)
 
for df in df_list: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fc in arcpy.mapping.ListLayers (mxd, "", df):
&amp;nbsp; if (fc.supports("DATASOURCE")) and (fc.dataSource.endswith(".shp")):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(fc)
print("List created")

# Check for borken datasource
for fc in list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.mapping.ListBrokenDataSources(fc):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.remove(fc)
print ("Broken data removed from list")

# Move fc to gdb
add_list = []
for fc in list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc_date = time.strftime("%Y%m%d", time.gmtime(os.path.getctime(fc.dataSource)))
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dsc = arcpy.Describe(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_temp = '_' + fc_date + '_' + fc.name + '_' + fc_prj
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_name = arcpy.ValidateTableName(out_temp)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print ('Created ' + out_name + ' to ' + gdb_full_path)
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_temp = '_' + fc_date + '_' + fc.name + '_' + 'UNKNOWN'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_name = arcpy.ValidateTableName(out_temp)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print ('Created ' + out_name + ' to ' + gdb_full_path)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FeatureClassToFeatureClass_conversion(fc, fd_path, out_name)
&amp;nbsp;&amp;nbsp;&amp;nbsp; replace_name = fd_path + '\\' + out_name
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc.replaceDataSource (gdb_full_path, "FILEGDB_WORKSPACE", out_name)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print ('Replaced data source ' + out_name + ' in ' + gdb_full_path)


# Create a new MXD
new_mxd = os.path.splitext(gdb_full_path)[0] + '\\' + 'MXD' + '\\' +&amp;nbsp; time.strftime("%Y%m%d", mxd_date )+ '_' + (mxd_name)
mxd.saveACopy(new_mxd)
print ('Created new MXD ' + new_mxd + ' in ' + ws)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 15:59:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77013#M6236</guid>
      <dc:creator>LucaMoiana</dc:creator>
      <dc:date>2021-12-12T15:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: ListBrokenDataSources not working</title>
      <link>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77014#M6237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried to reproduce your issue by simplifying your code.&amp;nbsp; It works.&amp;nbsp; I tested on 10.1 final.&amp;nbsp; I added two shapefiles to a new MXD.&amp;nbsp; I renamed one of them so it would appear broken in the MXD.&amp;nbsp; I created a new, empty file GDB.&amp;nbsp; Finally I ran the following, simplified code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Temp\Shapefiles.mxd")# Create a list of SHP in mxd 
list = []
df_list = arcpy.mapping.ListDataFrames(mxd)
 
for df in df_list: 
&amp;nbsp; for fc in arcpy.mapping.ListLayers(mxd, "", df):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fc.supports("DATASOURCE")) and (fc.dataSource.endswith(".shp")):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(fc)
print list

# Check for broken datasource
for fc in list:
&amp;nbsp; if arcpy.mapping.ListBrokenDataSources(fc):
&amp;nbsp;&amp;nbsp;&amp;nbsp; list.remove(fc)
print list

# Move fc to gdb
ws = r"C:\Temp\Temp.gdb"
for fc in list:
&amp;nbsp; dsc = arcpy.Describe(fc)
&amp;nbsp; arcpy.FeatureClassToFeatureClass_conversion(fc, ws, fc.name)
&amp;nbsp; fc.replaceDataSource (ws, "FILEGDB_WORKSPACE", fc.name)

# Create a new MXD
mxd.saveACopy(r"C:\Temp\Shapefiles2.mxd")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One possible issue is that you are running the code multiple times and the FCs may already exist in the output GDB.&amp;nbsp; You need to remove those manually ahead of time or check to see if they exist and remove them with code before the FeatureClassToFeatureClass function is called.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:58:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77014#M6237</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2021-12-10T22:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: ListBrokenDataSources not working</title>
      <link>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77015#M6238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I tried to reproduce your issue by simplifying your code.&amp;nbsp; It works.&amp;nbsp; I tested on 10.1 final.&amp;nbsp; I added two shapefiles to a new MXD.&amp;nbsp; I renamed one of them so it would appear broken in the MXD.&amp;nbsp; I created a new, empty file GDB.&amp;nbsp; Finally I ran the following, simplified code:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Temp\Shapefiles.mxd")# Create a list of SHP in mxd 
list = []
df_list = arcpy.mapping.ListDataFrames(mxd)
 
for df in df_list: 
&amp;nbsp; for fc in arcpy.mapping.ListLayers(mxd, "", df):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (fc.supports("DATASOURCE")) and (fc.dataSource.endswith(".shp")):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; list.append(fc)
print list

# Check for broken datasource
for fc in list:
&amp;nbsp; if arcpy.mapping.ListBrokenDataSources(fc):
&amp;nbsp;&amp;nbsp;&amp;nbsp; list.remove(fc)
print list

# Move fc to gdb
ws = r"C:\Temp\Temp.gdb"
for fc in list:
&amp;nbsp; dsc = arcpy.Describe(fc)
&amp;nbsp; arcpy.FeatureClassToFeatureClass_conversion(fc, ws, fc.name)
&amp;nbsp; fc.replaceDataSource (ws, "FILEGDB_WORKSPACE", fc.name)

# Create a new MXD
mxd.saveACopy(r"C:\Temp\Shapefiles2.mxd")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;One possible issue is that you are running the code multiple times and the FCs may already exist in the output GDB.&amp;nbsp; You need to remove those manually ahead of time or check to see if they exist and remove them with code before the FeatureClassToFeatureClass function is called.&lt;BR /&gt;&lt;BR /&gt;Jeff&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Jeff,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a lot for your reply.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Layers can't be in the gdb dataset cause, in the first part of the script a I create a new feature dataset.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:58:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77015#M6238</guid>
      <dc:creator>LucaMoiana</dc:creator>
      <dc:date>2021-12-10T22:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: ListBrokenDataSources not working</title>
      <link>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77016#M6239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;A new feature dataset or a new GDB?&amp;nbsp; Feature classes with the same name can't exist in two different feature datasets in the same GDB.&amp;nbsp; I.e., all feature classes in a GDB must have a unique name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Sep 2012 12:59:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77016#M6239</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2012-09-10T12:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: ListBrokenDataSources not working</title>
      <link>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77017#M6240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;A new feature dataset or a new GDB?&amp;nbsp; Feature classes with the same name can't exist in two different feature datasets in the same GDB.&amp;nbsp; I.e., all feature classes in a GDB must have a unique name.&lt;BR /&gt;&lt;BR /&gt;Jeff&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;New feature dataset in an existing GDB.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Still struggling...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Sep 2012 07:50:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77017#M6240</guid>
      <dc:creator>LucaMoiana</dc:creator>
      <dc:date>2012-09-11T07:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: ListBrokenDataSources not working</title>
      <link>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77018#M6241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;New feature dataset in an existing GDB.&lt;BR /&gt;&lt;BR /&gt;Still struggling...&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Apologies,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I just found out that I forgot this part in my script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#################
# REPLACE DATASOURCE
new_path = 'I:\\20120208_Backup_disco_E\\'
mxd.findAndReplaceWorkspacePaths('E:\\', new_path)
arcpy.RefreshTOC()
Sorry again&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:58:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77018#M6241</guid>
      <dc:creator>LucaMoiana</dc:creator>
      <dc:date>2021-12-10T22:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: ListBrokenDataSources not working</title>
      <link>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77019#M6242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi guys,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using version 10 and I just noticed that this code (ListBrokenDataSources only) works properly only in python window.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I run the .py file outside ArcGIS, it lists "all" the layers in the mxd and not the the broken one only for several runs, and after a while, it reports the correct broken layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could any one of you kindly let me know why I am experiencing this issue?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Chris&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Oct 2012 02:10:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77019#M6242</guid>
      <dc:creator>ChrisPedrezuela</dc:creator>
      <dc:date>2012-10-22T02:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: ListBrokenDataSources not working</title>
      <link>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77020#M6243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Chris,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I could not reproduce on 10.0 SP5.&amp;nbsp; What version/service pack are you running?&amp;nbsp; Could you provide a script and a description of the type of datasets in your MXD?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Oct 2012 13:47:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77020#M6243</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2012-10-22T13:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: ListBrokenDataSources not working</title>
      <link>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77021#M6244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jeff. I just used the sample code provided in the help docs for listbrokendatasources. I currently do not have a service pack installed so ill try to get one or maybe test on a pc with 10.1 and see what happens.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Chris&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Oct 2012 17:05:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listbrokendatasources-not-working/m-p/77021#M6244</guid>
      <dc:creator>ChrisPedrezuela</dc:creator>
      <dc:date>2012-10-22T17:05:32Z</dc:date>
    </item>
  </channel>
</rss>

