Skip to content

Instantly share code, notes, and snippets.

@M-Bryant
Created November 26, 2015 23:33
Show Gist options
  • Save M-Bryant/61ab1add37245b7d8a1b to your computer and use it in GitHub Desktop.
Save M-Bryant/61ab1add37245b7d8a1b to your computer and use it in GitHub Desktop.
arcpy: create_output_gdb
import os
import arcpy
def create_output_gdb(parent_folder, gdb_name):
"""Creates a new gdb in the folder
"""
arcpy.AddMessage("Checking output workspace...")
gdb_path = os.path.join(parent_folder, gdb_name + ".gdb")
# Generate a unique name if the gdb already exists
if arcpy.Exists(gdb_path):
arcpy.AddWarning(" " + gdb_path + " already exists...creating a unique name for the workspace")
unique_name = arcpy.CreateUniqueName(gdb_name + ".gdb", parent_folder)
gdb_path = unique_name
arcpy.AddMessage("Creating GDB: " + gdb_path)
arcpy.management.CreateFileGDB(os.path.dirname(gdb_path), os.path.basename(gdb_path))
return str(gdb_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment