Pyrhon variable working outside of function, but not inside
Question: I have an issue where I am trying to copy feature classes into a geodatabase.
I am looping through all the feature classes in the folder and copying only
the polygon feature classes. My problem is, that when I copy the first polygon
feature class it renames it 'shp', and then tries to name the second 'shp' as
well. The variable `fcname` returns the full feature class names
('counties.shp' and 'new_mexico.shp') outside of the copy function, but it
does not work properly inside the function.

The code below has the function that I want to run commented out to test the
`fcname` variable. There are five feature classes in the folder with two of
them being polygon feature classes. When uncommented the code runs all the way
through the first polygon feature class where `fcname` results in 'shp'
instead of 'counties.shp'. It does the same for the second feature class which
results in an error since 'shp' already exists in the `gdb`.

    
    
    import arcpy
    
    # Set initial variables with different pathnames available 
    # whether I am working on my home or work computer
    
    pathhome = "G:/ESRIScriptArcGIS/Python/Data/Exercise06"
    pathwork = "C:/ESRIPress/Python/Data/Exercise06"
    arcpy.env.workspace = pathwork
    gdbname ="NewDatabase.gdb"
    
    fclist = arcpy.ListFeatureClasses()
    
    # Create new gdb
    ##arcpy.management.CreateFileGDB(path, gdbname)
    newgdb = path + "/" + gdbname
    
    # Loop through list
    for fc in fclist:
        desc = arcpy.Describe(fc)
        fcname = desc.name
        outpath = newgdb + "/" + fcname
    
        # Check for polygon then copy
        if desc.shapeType == "Polygon":
            ##arcpy.management.CopyFeatures(fcname,outpath)
            ##print fcname + "copied."
            print fcname
        else:
            print "Not a polygon feature class"
    

Thank you to anyone who can help!


Answer: I found the answer to the problem. `CopyFeatures` does not want a full file
path in the `out_feature_class` argument. I stripped the ".shp" from the end
of the file path and it worked.

I also took Hector's advice and filtered down to just the polygons in the
`ListFeatureClasses` arguments, however, I still needed the loop to walk
through the resulting list and copy each feature class.

Here is the resulting code that worked.

    
    
    import arcpy
    
    # Set initial variables with different pathnames available
    # whether I am working on my home or work computer
    
    pathhome = "G:/ESRIScriptArcGIS/Python/Data/Exercise06"
    pathwork = "C:/ESRIPress/Python/Data/Exercise06"
    arcpy.env.workspace = pathwork
    gdbname ="NewDatabase.gdb"
    
    fclist = arcpy.ListFeatureClasses("", "Polygon")
    
    # Create new gdb
    arcpy.management.CreateFileGDB(pathwork, gdbname)
    newgdb = pathwork + "/" + gdbname
    
    # Loop through list
    for fc in fclist:
        desc = arcpy.Describe(fc)
        fcname = str(desc.name)
        outpath = newgdb + "/" + fcname.replace(".shp","")
    
    
    
        arcpy.management.CopyFeatures(fcname,outpath)
        print fcname + " has been copied."
    

