I want to copy all the rasters from folder in to Geodatabase with same name how can i do it, i tried through given script but does not copy with it's original name, what is problem in my code ? please help me ?
import arcpy
from arcpy import env
env.workspace = " "
rasterlist = arcpy.ListRasters()
for raster in rasterlist:
desc = arcpy.Describe(raster)
base_ext = desc.extension
if base_ext == '' ":
name = str(desc.basename)
arcpy.CopyRaster_management(name, CopyResults.gdb/name","DEFAULTS","0","9","","","8_BIT_UNSIGNED")
else:
name = str(desc.basename) + "." + str(desc.extension)
name1 = str(desc.basename)
arcpy.CopyRaster_management(name, CopyResults.gdb/name1","DEFAULTS","0","9","","","8_BIT_UNSIGNED")
print name
print "Copy all rasters successfully."
Solved! Go to Solution.
First of all you have set your workspace to nothing!
env.workspace = " "
This will make your ListRaster() function fail.
You then have incorrect syntax in the CopyRaster lines. For example you have:
arcpy.CopyRaster_management(name, CopyResults.gdb/name1","DEFAULTS","0","9","","","8_BIT_UNSIGNED")
It should be:
outname = "CopyResults.gdb/" + name1 arcpy.CopyRaster_management(name, outname ,"DEFAULTS","0","9","","","8_BIT_UNSIGNED")
First of all you have set your workspace to nothing!
env.workspace = " "
This will make your ListRaster() function fail.
You then have incorrect syntax in the CopyRaster lines. For example you have:
arcpy.CopyRaster_management(name, CopyResults.gdb/name1","DEFAULTS","0","9","","","8_BIT_UNSIGNED")
It should be:
outname = "CopyResults.gdb/" + name1 arcpy.CopyRaster_management(name, outname ,"DEFAULTS","0","9","","","8_BIT_UNSIGNED")
Actually this env.workspace = " " means i defined the workspace, not the empty workspace.
Well the last two lines are really helpful, Thanks.