Select to view content in your preferred language

Using ParsePath with Layers - Can you get 'real' file name?

643
2
Jump to solution
12-18-2023 07:22 AM
RandyMcGregor_BMcD
New Contributor III

I am using 'ParsePath' in a model and for 'Name' it returns whatever layer name I have given the layer in the TOC and for 'Path' it returns the group the layer is in (if it is in one). This is not helpful.

I would like to get the real file name - ie. DataPoints, not 'Points Collected in the field on 12/13/2023' 

If the user selects the file on disk, this problem is solved, but I'd rather have the convenience of pulling the layer in from the table of contents.

Is it possible with ParsePath to get the 'actual' file information? This can be done with Python, and I may make a Python tool, but just wondering of ModelBuilder ParsePath can work here.

Thank you,

Randy McGregor

0 Kudos
2 Solutions

Accepted Solutions
cpehlke
New Contributor

Hi Randy, 

I have a suggestion:

Instead of using Parse Path, you could try using something like this with Calculate Value:

Expression: FileName

Code Block:

LayerInput = '%LayerInput%'

desc = arcpy.Describe(LayerInput)

FileName = desc.baseName

The resulting Value should be the name of your actual file name.

Depending on your needs, you could change baseName to these other options available: https://pro.arcgis.com/en/pro-app/3.1/arcpy/functions/describe-object-properties.htm

View solution in original post

RandyMcGregor_BMcD
New Contributor III

Thank you! That worked. I appreciate it. Ended up looking like this:

RandyMcGregor_BMcD_0-1703004557316.png

 

View solution in original post

2 Replies
cpehlke
New Contributor

Hi Randy, 

I have a suggestion:

Instead of using Parse Path, you could try using something like this with Calculate Value:

Expression: FileName

Code Block:

LayerInput = '%LayerInput%'

desc = arcpy.Describe(LayerInput)

FileName = desc.baseName

The resulting Value should be the name of your actual file name.

Depending on your needs, you could change baseName to these other options available: https://pro.arcgis.com/en/pro-app/3.1/arcpy/functions/describe-object-properties.htm

RandyMcGregor_BMcD
New Contributor III

Thank you! That worked. I appreciate it. Ended up looking like this:

RandyMcGregor_BMcD_0-1703004557316.png