Select to view content in your preferred language

How to check if a FGDB exists in Python

12173
4
Jump to solution
10-05-2015 05:06 AM
JoseSanchez
Frequent Contributor

Hello everyone,

How can I check in Python if a FGDB exists?

Thanks

0 Kudos
1 Solution

Accepted Solutions
BerendVeldkamp
Frequent Contributor

arcpy.Exists(r"C:\Path\To\fgdb.gdb")

Will check if it exists, but not if it is a valid geodatabase. If you have an empty folder with a .gdb extension, it will still return True. So, depending on your needs this may or may not be what you want.

View solution in original post

4 Replies
BerendVeldkamp
Frequent Contributor

arcpy.Exists(r"C:\Path\To\fgdb.gdb")

Will check if it exists, but not if it is a valid geodatabase. If you have an empty folder with a .gdb extension, it will still return True. So, depending on your needs this may or may not be what you want.

NeilAyres
MVP Alum

So if you also want to make sure it is a valid fgdb, look at arcpy.Describe("path/to/f.gdb") and check its dataType

== "Workspace"

BerendVeldkamp
Frequent Contributor

Exactly. And if you want to exclude other types of workspace, you could check the workspaceType property of the describe object, or even workspaceFactoryProgID.

IanMurray
Honored Contributor

Have you tried using arcpy.Exists?

ArcGIS Help (10.2, 10.2.1, and 10.2.2)

From the help

Determines the existence of the specified data object. Tests for the existence of feature classes, tables,
datasets, shapefiles, workspaces, layers, and files in the current workspace. The function returns a Boolean indicating if the element exists.