Solved! Go to Solution.
just wondering if I am missing anything behind the scenes?
just wondering if I am missing anything behind the scenes?
import arcpy
import os
import shutil
source_dir = r"source\dir"
arcpy.env.workspace = source_dir
table = r"selection_table"
outDirBase = r"output\folder"
if not os.path.exists(outDirBase):
os.mkdir(outDirBase)
def GetList(table):
name_list = []
s_curs = arcpy.SearchCursor(table)
for row in s_curs:
name = row.Name
name_final = "XX_"+name.split("_")[1]
name_list.append(name_final)
return name_list
nts_list = GetList(table)
dir_list = [("bare_earth_DEM_ascii","be"),
("bare_earth_hillshade_tif","be"),
("full_feature_DSM_ascii","ff"),
("full_feature_hillshade_tif","ff"),
("intensity_image_tif","ii")]
# Get directory name and associated file prefix from tuple list
for directory,pref in dir_list:
# Create a variable to hold the full path to the export directory
new_dir = os.path.join(outDirBase,directory)
# If this folder doesn't exist, create it
if not os.path.exists(new_dir):
os.mkdir(new_dir)
# Create a variable to hold the full path to the source directory
in_dir = os.path.join(source_dir,directory)
# Loop through grid locations in the list of selected grids
for nts in nts_list:
# Assign the associated prefix to the current grid in the list
var_in = pref+nts[2:]
# Create a list of files in the source directory to test against
file_list = os.listdir(in_dir)
# Loop through all files in the source directory
for filename in file_list:
# If the current file matches the
if filename.startswith(var_in):
print "copying {0}".format(filename)
shutil.copy2(os.path.join(in_dir,filename),os.path.join(new_dir,filename))