<?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 Delete metadata for every geodatabase layer in a sub folder in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/delete-metadata-for-every-geodatabase-layer-in-a/m-p/1337259#M73935</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to delete the geoprocessing history of every feature classes in several geodatabases within a particular directory on my machine.&amp;nbsp; I can delete the geoprocessing history of a single feature class, but I currently am unable to walk through every directory and geodatabase.&lt;/P&gt;&lt;P&gt;Please let me know how I can modify the second script to delete the geoprocessing history of several geodatabases.&lt;/P&gt;&lt;P&gt;Thank You&lt;/P&gt;&lt;P&gt;########&lt;/P&gt;&lt;P&gt;CODE TO DELETE GEOPROCESSING HISTORY OF A SINGLE FEATURE CLASS (WORKS)&lt;/P&gt;&lt;P&gt;########&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;# Create a metadata object for the feature class&lt;BR /&gt;md = arcpy.metadata.Metadata(r'C:\mysubfolder\mygeodatabase.gdb\myfeatureclass') # Delete the 'GPHISTORY' metadata item&lt;BR /&gt;print(md.description)&lt;BR /&gt;md.deleteContent('GPHISTORY')&lt;BR /&gt;# Save the updated metadata&lt;BR /&gt;md.save()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;####ESRI PROVIDED CODE TO WALK THROUGH EACH FOLDER, GEODATABASE, FEATURE CLASS (NOT WORKING YET)&lt;/P&gt;&lt;P&gt;#####################&lt;/P&gt;&lt;P&gt;import arcpy, os&lt;BR /&gt;rootDir = r'C:\mysubfolder'&lt;BR /&gt;gdbList = []&lt;BR /&gt;for dirPath, dirNames, fileNames in os.walk(rootDir, topdown=True):&lt;BR /&gt;&amp;nbsp; if dirPath.endswith(".gdb") or ".gdb." in dirPath:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gdbList.append(dirPath)&lt;BR /&gt;for gdb in gdbList:&lt;BR /&gt;&amp;nbsp; arcpy.env.workspace = gdb&lt;BR /&gt;&amp;nbsp; datasetList = arcpy.ListDatasets('*','Feature')&lt;BR /&gt;&amp;nbsp; fcList = arcpy.ListFeatureClasses()&lt;BR /&gt;&amp;nbsp; for fc in fcList:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FC = arcpy.env.workspace+"\\"+fc&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(FC)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; md = arcpy.metadata.Metadata(FC)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print (md)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(md.description) #test to see if we can pull the description of the current layer&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(md.credits) #test to see if we can pull the description of the current layer&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(md.accessConstraints) #test to see if we can pull the description of the current layer&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; md.deleteContent('GPHISTORY') #delete GP history&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; md.save() #save metadata with the history removed&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Deleted")&lt;BR /&gt;&amp;nbsp; for dataset in datasetList:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = dataset&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcList = arcpy.ListFeatureClasses()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for fc in fcList:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FC = arcpy.env.workspace+"\\"+fc&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(FC)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; md = arcpy.metadata.Metadata(FC)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; md.deleteContent('GPHISTORY')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; md.save()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Deleted")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = gdb&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Oct 2023 13:30:51 GMT</pubDate>
    <dc:creator>LyonMNGIS</dc:creator>
    <dc:date>2023-10-12T13:30:51Z</dc:date>
    <item>
      <title>Delete metadata for every geodatabase layer in a sub folder</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/delete-metadata-for-every-geodatabase-layer-in-a/m-p/1337259#M73935</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to delete the geoprocessing history of every feature classes in several geodatabases within a particular directory on my machine.&amp;nbsp; I can delete the geoprocessing history of a single feature class, but I currently am unable to walk through every directory and geodatabase.&lt;/P&gt;&lt;P&gt;Please let me know how I can modify the second script to delete the geoprocessing history of several geodatabases.&lt;/P&gt;&lt;P&gt;Thank You&lt;/P&gt;&lt;P&gt;########&lt;/P&gt;&lt;P&gt;CODE TO DELETE GEOPROCESSING HISTORY OF A SINGLE FEATURE CLASS (WORKS)&lt;/P&gt;&lt;P&gt;########&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;# Create a metadata object for the feature class&lt;BR /&gt;md = arcpy.metadata.Metadata(r'C:\mysubfolder\mygeodatabase.gdb\myfeatureclass') # Delete the 'GPHISTORY' metadata item&lt;BR /&gt;print(md.description)&lt;BR /&gt;md.deleteContent('GPHISTORY')&lt;BR /&gt;# Save the updated metadata&lt;BR /&gt;md.save()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;####ESRI PROVIDED CODE TO WALK THROUGH EACH FOLDER, GEODATABASE, FEATURE CLASS (NOT WORKING YET)&lt;/P&gt;&lt;P&gt;#####################&lt;/P&gt;&lt;P&gt;import arcpy, os&lt;BR /&gt;rootDir = r'C:\mysubfolder'&lt;BR /&gt;gdbList = []&lt;BR /&gt;for dirPath, dirNames, fileNames in os.walk(rootDir, topdown=True):&lt;BR /&gt;&amp;nbsp; if dirPath.endswith(".gdb") or ".gdb." in dirPath:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gdbList.append(dirPath)&lt;BR /&gt;for gdb in gdbList:&lt;BR /&gt;&amp;nbsp; arcpy.env.workspace = gdb&lt;BR /&gt;&amp;nbsp; datasetList = arcpy.ListDatasets('*','Feature')&lt;BR /&gt;&amp;nbsp; fcList = arcpy.ListFeatureClasses()&lt;BR /&gt;&amp;nbsp; for fc in fcList:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FC = arcpy.env.workspace+"\\"+fc&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(FC)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; md = arcpy.metadata.Metadata(FC)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print (md)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(md.description) #test to see if we can pull the description of the current layer&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(md.credits) #test to see if we can pull the description of the current layer&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(md.accessConstraints) #test to see if we can pull the description of the current layer&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; md.deleteContent('GPHISTORY') #delete GP history&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; md.save() #save metadata with the history removed&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Deleted")&lt;BR /&gt;&amp;nbsp; for dataset in datasetList:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = dataset&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcList = arcpy.ListFeatureClasses()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for fc in fcList:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FC = arcpy.env.workspace+"\\"+fc&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(FC)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; md = arcpy.metadata.Metadata(FC)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; md.deleteContent('GPHISTORY')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; md.save()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Deleted")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = gdb&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2023 13:30:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/delete-metadata-for-every-geodatabase-layer-in-a/m-p/1337259#M73935</guid>
      <dc:creator>LyonMNGIS</dc:creator>
      <dc:date>2023-10-12T13:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: Delete metadata for every geodatabase layer in a sub folder</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/delete-metadata-for-every-geodatabase-layer-in-a/m-p/1388943#M79551</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure if you figured out the code or not since you've posted this but I too was having a similar problem. I figured out that you need to reset the workspace so that way it'll look through other datasets for feature classes in a gdb. I made a python toolbox that removes thumbnails and gphistory for every feature class in a gdb.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import os&lt;BR /&gt;from arcpy import metadata as md&lt;/P&gt;&lt;P&gt;class Toolbox:&lt;BR /&gt;def __init__(self):&lt;BR /&gt;"""Define the toolbox (the name of the toolbox is the name of the&lt;BR /&gt;.pyt file)."""&lt;BR /&gt;self.label = "Toolbox"&lt;BR /&gt;self.alias = "toolbox"&lt;/P&gt;&lt;P&gt;# List of tool classes associated with this toolbox&lt;BR /&gt;self.tools = [Tool]&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;class Tool:&lt;BR /&gt;def __init__(self):&lt;BR /&gt;"""Define the tool (tool name is the name of the class)."""&lt;BR /&gt;self.label = "GeoprocessingHistoryDeleter"&lt;BR /&gt;self.description = ""&lt;/P&gt;&lt;P&gt;def getParameterInfo(self):&lt;BR /&gt;"""Define the tool parameters."""&lt;BR /&gt;params = []&lt;/P&gt;&lt;P&gt;# Add a parameter for geodatabase file path&lt;BR /&gt;param = arcpy.Parameter(&lt;BR /&gt;displayName="Geodatabase Path",&lt;BR /&gt;name="geodatabase_path",&lt;BR /&gt;datatype="DEWorkspace",&lt;BR /&gt;parameterType="Required",&lt;BR /&gt;direction="Input")&lt;BR /&gt;params.append(param)&lt;/P&gt;&lt;P&gt;return params&lt;/P&gt;&lt;P&gt;def isLicensed(self):&lt;BR /&gt;"""Set whether the tool is licensed to execute."""&lt;BR /&gt;return True&lt;/P&gt;&lt;P&gt;def updateParameters(self, parameters):&lt;BR /&gt;"""Modify the values and properties of parameters before internal&lt;BR /&gt;validation is performed. This method is called whenever a parameter&lt;BR /&gt;has been changed."""&lt;BR /&gt;return&lt;/P&gt;&lt;P&gt;def updateMessages(self, parameters):&lt;BR /&gt;"""Modify the messages created by internal validation for each tool&lt;BR /&gt;parameter. This method is called after internal validation."""&lt;BR /&gt;return&lt;/P&gt;&lt;P&gt;def execute(self, parameters, messages):&lt;BR /&gt;"""The source code of the tool."""&lt;BR /&gt;# Get the geodatabase path parameter&lt;BR /&gt;geodatabase_path = parameters[0].valueAsText&lt;BR /&gt;db_type = "SQL" # Set this to either "SQL", "Oracle", or "Postgres" if your db has spatial views. If not, you may set it to "".&lt;/P&gt;&lt;P&gt;def RemoveHistory(geodatabase_path):&lt;BR /&gt;# Removes GP History for feature dataset stored feature classes, and feature classes in the File Geodatabase.&lt;BR /&gt;arcpy.env.workspace = geodatabase_path&lt;BR /&gt;for fds in arcpy.ListDatasets('', 'feature') + ['']:&lt;BR /&gt;for fc in arcpy.ListFeatureClasses('', '', fds):&lt;BR /&gt;data_path = os.path.join(geodatabase_path, fds, fc)&lt;BR /&gt;if isNotSpatialView(geodatabase_path, fc):&lt;BR /&gt;removeMetaData(data_path)&lt;BR /&gt;arcpy.AddMessage("Removed the geoprocessing metadata from: {0}".format(fc))&lt;BR /&gt;removeMetaData(geodatabase_path)&lt;BR /&gt;arcpy.AddMessage("Removed the geoprocessing metadata from: {0}".format(geodatabase_path))&lt;/P&gt;&lt;P&gt;def isNotSpatialView(geodatabase_path, fc):&lt;BR /&gt;# Determines if the item is a spatial view and if so returns True to listFcsInGDB()&lt;BR /&gt;if db_type != "":&lt;BR /&gt;# Check if the feature class is not a spatial view&lt;BR /&gt;return True&lt;BR /&gt;else:&lt;BR /&gt;return True&lt;/P&gt;&lt;P&gt;def removeMetaData(data_path):&lt;BR /&gt;# Get the metadata for the dataset&lt;BR /&gt;tgt_item_md = md.Metadata(data_path)&lt;BR /&gt;# Delete all geoprocessing history from the item's metadata&lt;BR /&gt;if not tgt_item_md.isReadOnly:&lt;BR /&gt;tgt_item_md.deleteContent('GPHISTORY')&lt;BR /&gt;tgt_item_md.deleteContent('THUMBNAIL')&lt;BR /&gt;tgt_item_md.save()&lt;/P&gt;&lt;P&gt;if __name__ == "__main__":&lt;BR /&gt;RemoveHistory(geodatabase_path)&lt;BR /&gt;arcpy.AddMessage("Done Done")&lt;BR /&gt;return&lt;/P&gt;&lt;P&gt;def postExecute(self, parameters):&lt;BR /&gt;"""This method takes place after outputs are processed and&lt;BR /&gt;added to the display."""&lt;BR /&gt;return&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Feb 2024 17:17:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/delete-metadata-for-every-geodatabase-layer-in-a/m-p/1388943#M79551</guid>
      <dc:creator>WyattPowers</dc:creator>
      <dc:date>2024-02-29T17:17:52Z</dc:date>
    </item>
  </channel>
</rss>

