Using the FeatureToPoint tool I've having difficulty calling just the name for the shapefile without the extension or path. Here is the part of the script that I'm creating that I am stuck on.

eg. C:\user\shapefiles\polygon.shp I just want the word polygon

import arcpy

file1 = arcpy.GetParameterAsText(1) # this is a .shp file 
savepointlocation = arcpy.GetParameterAsText(2)

arcpy.FeatureToPoint_management(file1, save1, "INSIDE")

The problem is that its calling for the path of C:\user\shapefiles\polygon.shp and not just the name polygon.

I'm new and I'm sure there is some function or way to just call the name of the file without the path or the .shp in the file.

1 Answer 1


You can do this using 2 os.path functions (splitext and basename):

import os
os.path.splitext(os.path.basename(r'C:\user\shapefiles\polygon.shp'))[0] # returns 'polygon'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.