This is my python script code in ArcGIS 10.3;
projectResult = arcpy.Project_management(fc, outFolder + "\\" + fc, template)
# Name of shapefiles re-projected in result dialog window
arcpy.AddMessage(projectResult)
Which gives me this in the geoprocessing dialog result box;
C:\GIS_Result\abc.shp
C:\GIS_Result\1234.shp
C:\GIS_Result\zyx.shp
C:\GIS_Result\987.shp
Can I remove the filepath to give me just the filename?;
abc.shp
1234.shp
zyx.shp
987.shp
Solved! Go to Solution.
Try using:
arcpy.AddMessage(fc
)
or
arcpy.AddMessage(projectResult.replace("
C:\GIS_Result\",""
)
I am not python expert. Hope this is helpful
Kishor
try a variant of this
>>> projectResult = [r'C:\GIS_Result\abc.shp',r'C:\GIS_Result\1234.shp',r'C:\GIS_Result\zyx.shp'] >>> msg = [out.split('\\')[-1] for out in projectResult] >>> msg ['abc.shp', '1234.shp', 'zyx.shp'] >>>
Try using:
arcpy.AddMessage(fc
)
or
arcpy.AddMessage(projectResult.replace("
C:\GIS_Result\",""
)
I am not python expert. Hope this is helpful
Kishor
not sure that is what he wants...
>>> for i in projectResult: ... i.replace("C:\\GIS_Result\\","") ... 'abc.shp' '1234.shp' 'zyx.shp' >>> projectResult ['C:\\GIS_Result\\abc.shp', 'C:\\GIS_Result\\1234.shp', 'C:\\GIS_Result\\zyx.shp'] >>>
it doesn't seem to change the list
and with this, I get an error message since projectResult is a list
>>> projectResult.replace("C:\GIS_Result\","") Traceback ( File "<interactive input>", line 1 projectResult.replace("C:\GIS_Result\","") ^ SyntaxError: EOL while scanning string literal >>>
Kishor,
arcpy.AddMessage(fc
) only gives me the name of 1 shapefile
and
arcpy.AddMessage(projectResult.replace("
C:\GIS_Result\",""
) doesn't work at all .
check my thread, that has already been pointed out, I was hoping he would correct it or offer a different solution should mine not be suitable
Dan,
I get [u'xyz.shp' ] as the output.
all that means is Unicode, it won't affect the ability to read the filename, or to use the print statement
>>> a = u'unicode_string' >>> a u'unicode_string' >>> print a unicode_string
Hi
Try os.path.basename(FileName) It works for unix too...
Have fun
Mody