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?
2 Answers
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
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