Please kindly advise the function of 1. short = shapefile[:score]2. %s.shp
import arcpy for shapefile in shapefileList: score = shapefile.find("_") short = shapefile[:score] arcpy.Copy_management(shapefile, "%s.shp" % short) arcpy.Delete_management(shapefile)
import arcpy # directory containing shapefiles to be renamed shapefile_dir = path = r'C:\ChangeShapefileNames\Shapefiles' arcpy.env.workspace = shapefile_dir shapefileList = arcpy.ListFeatureClasses() for shapefile in shapefileList: score = shapefile.find("_") short = shapefile[:score] arcpy.Copy_management(shapefile, "%s.shp" % short) arcpy.Delete_management(shapefile)
import os files = filter(os.path.isfile, os.listdir('')) for file in files: # Split on the extension. split = file.split(".") # Get the first 5 characters in the file name name = split[0][:5] # Extension ext = split[1] print "Renaming "+file+" to "+name+"."+ext os.rename(file, name+"."+ext)
System: ArcGIS 9.3I have five shapefiles with long names: A8923_Dis_shp.shp, A4592_Dis_shp.shp, A9820_Dis_shp.shp, A1276_Dis_shp.shp, A3726_Dis_shp.shpI want to make their names shorter, such asA8923.shp, A4592.shp, A9820.shp, A1276.shp, A3726.shp
import os import arcpy from arcpy import env # directory containing shapefiles to be renamed shapefile_dir = path = r'C:\ChangeShapefileNames\Shapefiles' env.workspace = shapefile_dir shapefileList = arcpy.ListFeatureClasses() for shapefile in shapefileList: # get the shapefile name and file extension fileName,fileExtension = os.path.splitext(shapefile) # replace the strings you want to fileName = fileName.replace("_Dis_shp","") fileName = fileName + fileExtension # rename the files arcpy.Rename_management(shapefile, fileName)
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.