How to check if a FGDB exists in Python

7518
4
Jump to solution
10-05-2015 05:06 AM
JoseSanchez
Occasional Contributor III

Hello everyone,

How can I check in Python if a FGDB exists?

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
BerendVeldkamp
Occasional Contributor II

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
Occasional Contributor II

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

NeilAyres
MVP Frequent Contributor

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
Occasional Contributor II

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
Frequent 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.