10

AS the title suggests, how can I whether a GDB file is valid using arcpy? One approach is, only checking the whether the name ends with .gdb, but that's not a robust approach. Because a normal file can be ended with .gdb, where GDBs are essentially folders to OS. So how can I do that?

8

The following code is used to List Workspaces, in this case, File Geodatabases. It does not check for the file extension .gdb, but is looking for its internal type. This should leave out directories with a .gdb extension, but which are not actually File GDB's.

import arcpy

arcpy.env.workspace = "C:/Data" 

# List all file geodatabases in the current workspace 
# 
workspaces = arcpy.ListWorkspaces("*", "FileGDB")
for workspace in workspaces: 
    # Print workspace name
    #
    print workspace
8

Where @Get Spatial's answer is partially correct, but it doesn't solve the problem directly. So answering my own question:

desc = arcpy.Describe(filePath)
print desc.dataType

It prints the type of the object given path is directing. For folders, it prints Folder and for geodatabases it prints Workspace

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.