Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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
share|improve this answer
up vote 6 down vote accepted

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

share|improve this answer
+1 - For finding an equally good solution! –  Get Spatial Jun 14 '12 at 14:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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