I am trying to automate a naming process that takes the file name from a list of file paths to name other folders, geodatabases, zipfiles, etc.
The problem I'm running into is that, I assume, I am trying to run string functions on list object and I can't figure out how to get the script to do what I need it to do.
For example, I have the file path C:\TEMP\Durham.shp. I want to name a geodatabase, folder, and zipfile "Durham". Instead I get a folder and geodatabase named "C".
Can someone take a look at my script and tel me what I'm doing wrong?
The following script is that last incarnation of several attempts.
I have also tried
The problem I'm running into is that, I assume, I am trying to run string functions on list object and I can't figure out how to get the script to do what I need it to do.
For example, I have the file path C:\TEMP\Durham.shp. I want to name a geodatabase, folder, and zipfile "Durham". Instead I get a folder and geodatabase named "C".
Can someone take a look at my script and tel me what I'm doing wrong?
The following script is that last incarnation of several attempts.
Code:
import arcpy, os
import zipfile
from arcpy import env
from os.path import basename
BASELAYERS = arcpy.GetParameterAsText(0)
CLIPLAYERS = arcpy.GetParameterAsText(1)
OUTFOLDERMASTER = arcpy.GetParameterAsText(2)
FILETYPES = ["*.shp", "*.dbf", "*.shx", "*.prj", "*.sbn", "*.sbx", "*.xml"]
env.workspace = OUTFOLDERMASTER
for LAYERS in CLIPLAYERS:
LAYERSSTR = ''.join(LAYERS)
BASENAME = LAYERSSTR.split("\\")[-1]
FOLDER = os.path.join(OUTFOLDERMASTER, BASENAME)
os.makedirs(FOLDER)
PGDBNAME = "NCFlood_Effective_" + BASENAME + "_PGDB.mdb"
arcpy.CreatePersonalGDB_management(FOLDER, PGDBNAME, "9.3")
PGDB = os.path.join(FOLDER,PGDBNAME)
for FILES in BASELAYERS:
FEATURENAMESTR = ''.join(FILES)
FEATURENAME = os.path.basename(FEATURENAMESTR)
SHAPEFILENAME = FEATURENAME + ".shp"
SHAPEFILE = os.path.join(FOLDER, SHAPEFILENAME)
arcpy.Clip_analysis(FILES, LAYERS, FEATURENAME)
arcpy.Clip_analysis(FILES, LAYERS, SHAPEFILE)
ZIPFILELIST = []
for TYPE in FILETYPES:
ZIPFILELIST.extend(glob.glob(FOLDER))
ZIPFILENAME = os.path.join(FOLDER, "NCFlood_Effective_" + FOLDERNAME + "_SHP.zip")
ARCHIVE = zipfile.ZipFile(ZIPFILENAME, "w")
for ZIP in ZIPFILELIST:
ARCHIVE.write(ZIP, os.path.basename(ZIP), zipfile.ZIP_DEFLATED)
ARCHIVE.close()
Code:
BASENAME = os.path.basename(LAYERS)
FOLDERNAME = os.path.splitext(BASENAME)[0]