Using a script to create a file geodatabase

You can run a Python script, calling the CreateFileGDB_management function, to create a file geodatabase.

You would do this if you are creating a file geodatabase from your ArcGIS client on a Linux machine or if you want to have a reusable, stand-alone script that you can alter slightly and use to create all your file geodatabases from Python.

Because Python scripts are running in Wine on your Linux box, directory paths should use the Windows path separator (\). In the examples provided, Z: is the root directory.

The following steps provide some examples of how you would use Python to create a file geodatabase:

Steps:
  1. Open a Python command prompt.
  2. Either run a stand-alone script or type commands directly into the interactive interpreter.

    In the first example, the createfgdb.py script contains the following information:

    # Import system modules
    import os
    import sys
    import arcpy
    
    # Set workspace
    env.workspace = "Z:\home\user\mydata"
    
    # Set local variables
    out_folder_path = "Z:\home\user\mydata"
    out_name = "myfgdb.gdb"
    
    # Execute CreateFileGDB
    arcpy.CreateFileGDB_Management(out_folder_path, out_name)
    

    After you alter the script to run at your site, you can call it from a command prompt:

    python createfgdb.py
    

    In this example, the Python is typed at the command prompt to create a file geodatabase (myfgdb.gdb) in the directory gdbs in the user's home directory on a Linux machine:

    import arcpy
    
    arcpy.CreateFileGDB_management("Z:\home\user\gdbs", "myfgdb.gdb")
    

    This example creates a version 9.3 file geodatabase (myoldfgdb.gdb) in the user's oldgdbs directory:

    import arcpy
    
    arcpy.CreateFileGDB_management("Z:\home\user\oldgdbs", "myoldfgdb.gdb", "9.3")
    

8/12/2013