shapefiles fail to load into file geodatabase

1458
4
01-10-2013 03:59 PM
GlenRouse
New Contributor III
I have a python script that used to work.  It's pretty basic.  There are two shape files I want to load into an empty file geodatabase.

The path to the geodatabase is "D:\PWWILD\MASTER\"

The name of the geodatabase is "MASTER.gdb"

The script actually creates the geodatabase prior to trying to load the shapefiles.  When I run the script "MASTER.gdb" is created.  When the script attempts to load the shape files they don't end up inside the geo db, a copy is made and ends up inside the folder "D:\PWWILD\"

Below is the script:

# MakeGDB.py creates the geodatabase "MASTER.GDB"
# Then shapefiles "cnddb.shp" & "cnddbpnt.shp" are loaded into
# the newly created GDB.

import arcgisscripting
gp = arcgisscripting.create()

gp.workspace = "D:/PWWILD/MASTER"
gp.toolbox = "management"
gp.CreateFileGDB("D:/PWWILD/MASTER", "MASTER.gdb")

# Put in error trapping in case an error occurs when running tool
try:
    # Set the workspace
    #gp.Workspace = "D:/PWWILD/M"
    gp.FeatureClassToGeodatabase("cnddb.shp;cnddbpnt.shp", "D:/PWWILD/MASTER/MASTER.gdb")

except:
    # If an error occurred print the message to the screen
    print gp.GetMessages()

I guess I'm wondering what is going on.  The script ran fine yesterday on this machine and it still runs fine on an older XP machine.

I ported the scripts from an XP machine which had ArcGIS 9.3.  Like I said they ran fine yesterday on the Win 7 machine.  Probably something I did, but I can't see it.  I changed the code thinking maybe because the newer machine runs 10.0 I should make sure it is compatible.  Here is that code.  It gives the same result.

# MakeGDB.py creates the geodatabase "MASTER.GDB"
# Then shapefiles "cnddb.shp" & "cnddbpnt.shp" are loaded into
# the newly created GDB.


# Import system modules
import arcpy
from arcpy import env

arcpy.CreateFileGDB_management("D:/PWWILD/MASTER", "MASTER.gdb")

# Set the workspace
env.workspace = "D:/PWWILD/MASTER"

# Set local variables
inFeatures = ["cnddb.shp", "cnddbpnt.shp"]
outLocation = "D:/PWWILD/MASTER/MASTER.gdb"

# Execute TableToGeodatabase
arcpy.FeatureClassToGeodatabase_conversion(inFeatures, outLocation)



New script does the same thing, shapefiles end up in the "PWWILD" folder instead of the geo db.

Hopefully someone has an explanation.

Glen
Tags (2)
0 Kudos
4 Replies
ChrisSnyder
Regular Contributor III
Not sure what's wrong with your code/machine, but there are many ways to skin a shapefile. Personally, I don't like using the env.workspace variable unless I have to (for example, if listing featureclasses in a FGDB). Also, I avoid using CAPS in file/folder names. This code "should" work:

import os, arcpy
rootDir = r"D:\pwwild\master"
fgdbName = "master.gdb"
fgdbPath = os.path.join(rootDir, fgdbName) 
arcpy.CreateFileGDB_management(rootDir, fgdbName)
shpList = ["cnddb.shp", "cnddbpnt.shp"] # I assume these are in rootDir
for shp in shpList:
    inFC = os.path.join(rootDir, shp)
    outFC = os.path.join(fgdbPath, shp.split(".")[0])
    arcpy.CopyFeatures_management(inFC, outFC)
0 Kudos
T__WayneWhitley
Frequent Contributor
I like the code Chris has provided.  As for the mystery why your code worked, then stopped, your rewrite looks fine except I'd stick with 'raw' strings.  May not fix your problem but try strings as in the following (also this convention was used by Chris) - make lower case if necessary:

r"D:\PWWILD\MASTER"

If that doesn't work try creating the gdb at a different root location than your input shps.
0 Kudos
GlenRouse
New Contributor III
Thanks I will give these suggestions a try.  I appreciate the help.
0 Kudos
GlenRouse
New Contributor III
The code Chris provided worked.  I am going to adopt the lowercase strategy for file/folders names from here on out.

Thanks again Chris and Wayne for your help.
0 Kudos