Copy files using python reading from an attribute table

4980
5
Jump to solution
06-04-2015 06:44 PM
ADREETATHAKUR
New Contributor

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()

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

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

View solution in original post

5 Replies
curtvprice
MVP Esteemed Contributor

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
DanPatterson_Retired
MVP Emeritus

Done Curtis​

ADREETATHAKUR
New Contributor

Thank you Curtis, it worked perfectly.

Adreeta

0 Kudos
ToddBlanchette
Occasional Contributor II

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.

ADREETATHAKUR
New Contributor

Thanks Todd, very helpful tip.

0 Kudos