I have names of Tiff files as a field in an attribute table of a feature class. I want to move only those files from hundreds of other files from the source folder to another folder. The attribute table has only .tiff extensions attached to the filenames but I need to copy all the associated files such as .aux, .ovr and .xml.
The script below is successful up to writing all the .tiff files but my issue is how to copy the rest of the associated files for each raster. Maybe fnmatch or glob module will to the job but I am not sure how to use them. Any help is appreciated.
Adreeta
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
import os
import arcpy
import os.path
import shutil
featureclass = "C:\\work_Data\\Export_Output.shp"
src = "C:\\Data\\UC_Training_Areas"
dst = "C:\\Data\\Script"
rows = arcpy.SearchCursor(featureclass)
row = rows.next()
while row:
print row.Label
shutil.move(os.path.join(src,str(row.Label)),dst)
row = rows.next()
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Solved! Go to Solution.
Please move this thread to Python. (This place is for help with the Geonet website.)
The way to move all the ancillary files with the tiff is to use arcpy to call the ArcGIS tool CopyRaster.
import os import arcpy featureclass = "C:\\work_Data\\Export_Output.shp" src = "C:\\Data\\UC_Training_Areas" dst = "C:\\Data\\Script" rows = arcpy.SearchCursor(featureclass) for row in rows: print row.Label arcpy.CopyRaster_management(os.path.join(src, row.Label), os.path.join(dst, row.Label)) del row, rows
Please move this thread to Python. (This place is for help with the Geonet website.)
The way to move all the ancillary files with the tiff is to use arcpy to call the ArcGIS tool CopyRaster.
import os import arcpy featureclass = "C:\\work_Data\\Export_Output.shp" src = "C:\\Data\\UC_Training_Areas" dst = "C:\\Data\\Script" rows = arcpy.SearchCursor(featureclass) for row in rows: print row.Label arcpy.CopyRaster_management(os.path.join(src, row.Label), os.path.join(dst, row.Label)) del row, rows
Done Curtis
Thank you Curtis, it worked perfectly.
Adreeta
As a note, if you're just copying the rasters exactly as they are (no change to compression, format, etc), then the arcpy.Copy_management might be the better tool. It's faster (I've seen 30sec vs 3 mins for TIF), still copies all the related files (ovr, etc), and I've seen the arcpy.CopyRaster_management tool change your file sizes due to the fact that raster pyramid creation is set to ON by default. You would have to make sure your environment settings are changed if you want to avoid this.
Thanks Todd, very helpful tip.