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()
BASENAME = os.path.basename(LAYERS) FOLDERNAME = os.path.splitext(BASENAME)[0]
Solved! Go to Solution.
>>>from os import path >>>text = r'C:\TEMP\Durham.shp' >>>path.dirname(text) 'C:\\TEMP' >>>path.basename(text) 'Durham.shp' >>>newfolderName = path.basename(text)[-4:] >>>newfolderName 'Durham' >>>newPath = path.join('C:\\newLocation', newfolderName) >>>newPath 'C:\\newLocation\\Durham'