Programmatically return Feature Class file size and date modified

17182
30
05-21-2013 06:19 AM
JohnDye
Occasional Contributor III
There doesn't appear to be a function in arcpy to return the file size of a feature class or it's date modified timestamp.

Anyone have any idea how to do this? I know there is a property somewhere because you can setup ArcCatalog to display the information. However, I want to see it returned in a Python Script so that I can write a two-way synchronization function.
Tags (2)
30 Replies
JohnDye
Occasional Contributor III
So digging around a little more, I found a nifty little featurecompare function in the management toolbox. It seems to give me a decent solution to flagging child fcs that are different from the parentfc. According to the the ArcGIS Resources Help File:

"The comparison tools result object will be 'true' when no differences are found and 'false' when differences are detected."

So I should be able to return a True or False from the result object. It seems however that my result object is not returning anything. Does it matter that the result object is a unicode string?

I dont understand why my result object is coming up empty.

CODE:
childfc = r"C:\Temp\MyGDB\Stores"
parentfc = r"\\sharedrive\ParentGDB\Stores"

result = arcpy.FeatureCompare_management(parentfc, childfc, "DID", "ATTRIBUTES_ONLY", "", "", "", "", "", "", "NO_CONTINUE_COMPARE")

print "Comparison Result is: " + result
result.GetOutput


Shell Results:
Comparison Result is:
<bound method Result.getOutput of <Result ''>>
0 Kudos
JohnDye
Occasional Contributor III
I dont understand why my result object is coming up empty.


Doh!
Index Values help...

CODE:
childfc = r"C:\Temp\MyGDB\Stores"
parentfc = r"\\sharedrive\ParentGDB\Stores"

result = arcpy.FeatureCompare_management(parentfc, childfc, "DID", "ATTRIBUTES_ONLY", "", "", "", "", "", "", "NO_CONTINUE_COMPARE")

print "Comparison Result is: " + result.getOutput(1)
result.GetOutput(1)


Shell Results:
Comparison Result is: false
u'false'
0 Kudos
VandanaRaghunathan
New Contributor III

Hello John,

Have you considered using editor tracking instead? This will create columns in the attribute table indicating the edits made to the feature class, this you can access using python.

About tracking an editor's changes to data—Help | ArcGIS for Desktop

Like mentioned in the previous posts, unless it is a shapefile, the date modified for file geodatabase feature class cannot be displayed in ArcCatalog. Even the edits made to the feature class, does not affect the time stamp on the geodatabase itself until all the locks are released (this is also considered an "edit" on the gdb) i.e. till the application is closed which may not be the time you stopped editing.

43164 - In ArcCatalog, why is the time stamp incorrect on the date modified field of a file geodatab...

Therefore, editor tracking is definitely better option if you want to track changes made to the feature class. Feature Compare essentially compares the properties of two feature classes in terms of geometry, attrribute, schema and spatial reference.

Hope this helps!

Thanks,

Best,

Vandana

0 Kudos
MattWilkie2
New Contributor II

wrt "the date modified for file geodatabase feature class cannot be displayed in ArcCatalog.": It works in in ArcCatalog 10.3:

2015-05-20 14_39_03-ArcCatalog - D__s_test.gdb.png

(editor tracking is still a good idea).

0 Kudos
KimOllivier
Occasional Contributor III

Have people noticed that these statistics do not appear until metadata is built for the geodatabase and needs to be refreshed to get featurecounts and dates? That is the clue on how to get these details programatically. You can't read the imbedded metadata easily because it is stored as a BLOB, but you can export it to XML and then read it with Python. All the tools are there to export metadata and the standard python module Xtree can extract what you need. No need for ArcObjects at all.

1. arcpy.management.SynchronizeMetadata(....)

2.arcpy.conversion.ExportMetadata(...)

3. import xml.etree.ElementTree as ET

  tree = ET.parse(xmlfile)

  [get required elements]

curtvprice
MVP Esteemed Contributor
0 Kudos
JohnDye
Occasional Contributor III

Nice!

0 Kudos
JohnGaiot
Occasional Contributor

Unfortunately none of these methods (viewing in ArcCatalog or exporting metadata) seem to work for raster datasets inside file geodatabases...

ArcCatalog Example

0 Kudos
DanielBauer
New Contributor
Hello,

I tried juanf.martinez.carmona's code using comtypes.client and it worked fine on a system running ArcGIS 10.0. Sadly running the script on an ArcGIS 10.1 system leads to the following error:

Traceback (most recent call last):
  File "D:\pyTest\FeatureClass_date.py", line 12, in <module>
    pwf = comtypes.client.CreateObject(esriDataSourcesGDB.FileGDBWorkspaceFactory, interface=esriGeodatabase.IWorkspaceFactory)
AttributeError: 'module' object has no attribute 'FileGDBWorkspaceFactory'

Does anybody have an idea, what might be the problem here?
0 Kudos
MicahBabinski
Occasional Contributor III

Getting the modified date of a .gdb table/feature class took some real acrobatics, but I was finally able to get it done. I started out with zero ArcObjects experience but a good dose of Python and arcpy.

Step one was to carefully follow the instructions here:

How do I access ArcObjects from Python? - Geographic Information Systems Stack Exchange

and here:

python - ArcObjects + comtypes at 10.1 - Geographic Information Systems Stack Exchange

Once I got the "create point" code working (from the example in the first link), I opened up the Snippets.py code and inserted the following function under the *** Standalone *** section, where gdb is the full path to the gdb and tableName is the table name:

def GetModifiedDate(gdb, tableName):    
    # Setup    
    GetStandaloneModules()    
    InitStandalone()    
    import comtypes.gen.esriSystem as esriSystem    
    import comtypes.gen.esriGeoDatabase as esriGeoDatabase    
    import comtypes.gen.esriDataSourcesGDB as esriDataSourcesGDB    

    # Open the FGDB    
    pWS = Standalone_OpenFileGDB(gdb)  
  
    # Create empty Properties Set    
    pPropSet = NewObj(esriSystem.PropertySet, esriSystem.IPropertySet)    
    pPropSet.SetProperty("database", gdb)    

    # Cast the FGDB as IFeatureWorkspace    
    pFW = CType(pWS, esriGeoDatabase.IFeatureWorkspace)    

    # Open the table    
    pTab = pFW.OpenTable(tableName)    

    # Cast the table as a IDatasetFileStat    
    pDFS = CType(pTab, esriGeoDatabase.IDatasetFileStat)    

    # Get the date modified    
    return pDFS.StatTime(2)

Finally, I created a script that implemented the function (set up for a custom script tool but could be used as a stand-alone as well):

import Snippets
import datetime
import arcpy
import sys

# User Params
file_gdb = arcpy.GetParameterAsText(0) # Path to FGDB
table_name = arcpy.GetParameterAsText(1) # Table or feature class name

arcpy.env.workspace = file_gdb

if file_gdb.split(".")[-1] != "gdb":
    arcpy.AddMessage("The input workspace is not a file geodatabase!")
    sys.exit()

def doIt(file_gdb, table_name):

    # Call GetModifiedDate function to get the number of seconds
    num_seconds = Snippets.GetModifiedDate(file_gdb, arcpy.Describe(table_name).baseName)

    # Translate the number of seconds into a formatted date
    date_modified = datetime.datetime.fromtimestamp(num_seconds).strftime('%Y-%m-%d %H:%M:%S')

    # Report the result
    arcpy.AddMessage(date_modified)
    return date_modified

doIt(file_gdb, arcpy.Describe(table_name).baseName)

I sincerely hope this helps! Thanks to all the people who got me to an actual solution.