Take the 2-minute tour ×
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
1  
Based on the answer you provided, I would ask that in the future, you provide a more detailed question. The script that I provided, cycles through the "Valid", File GDB's, which is what you asked about in the first sentence of your question. If you wanted a list of all workspace, with their type, not just the FileGDB, you need to ask for that. This may help you get more answers, and help you improve your acceptance rate. –  Get Spatial Jun 14 '12 at 14:58
add comment

2 Answers 2

up vote 3 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
add comment

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
add comment

Your Answer

 
discard

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.