Parse Path (ModelBuilder)

Summary

Parses an input into its file name, extension, path, and the last workspace name. The output can be used as an inline variable in the output name of other tools.

Learn how Parse Path works in ModelBuilder

Usage

  • This tool is only available from the ModelBuilder ribbon for use in models. The tool is not available from the Geoprocessing pane or from Python.

  • More than one variable name can be added to create unique names for the output, for example, C:\Temp\Out_%Name%_%Workspace Name%.

  • If the input to the Parse Path tool is C:\1Tool Data\City Roads.shp, it is parsed into the following outputs:

    ParseResult
    Path C:\1Tool Data
    NameCity Roads
    Extensionshp
    Workspace Name1Tool Data

    If the Format Name, Extension and Workspace parameter is checked, the path above will be parsed into the following outputs:

    ParseResult
    Path C:\1Tool Data
    NameCity_Roads
    Extensionshp
    Workspace Name_1Tool_Data

  • The same functionality can be accessed in scripting with the Python os module. For example, if you pass an input variable:

    inData = r"C:\1Tool Data\City Roads.shp", then

    • To get the name City Roads
      import os
      name = os.path.basename(inData)
    • To get the path C:\1Tool Data
      import os
      path = os.path.dirname(inData)
    • To get the file extension shp
      import os
      ext = os.path.splitext(inData)[1][1:]
    • To get the workspace name 1Tool Data
      import os
      folder = os.path.basename(os.path.dirname(inData))

    To parse paths in a similar way to when the Format Name, Extension and Workspace parameter is checked:

    • To get the name City_Roads
      import os
      import re
      name = os.path.basename(inData)
      name = re.sub('[^0-9a-zA-Z]+', '_', name)
      if name[0].isdigit():
          name = "_" + name
    • To get the path C:\1Tool Data
      import os
      path = os.path.dirname(inData)
    • To get the file extension shp
      import os
      ext = os.path.splitext(inData)[1][1:]
    • To get the workspace name _1Tool_Data
      import os
      import re
      folder = os.path.basename(os.path.dirname(inData))
      folder = re.sub('[^0-9a-zA-Z]+', '_', folder)
      if folder[0].isdigit():
          folder = "_" + folder

  • The Path output of Parse Path has a workspace data type and can be connected directly as an input to the Create Feature Class tool's Feature Class Location parameter, which accepts a workspace data type as input. For tools such as Copy that do not have a workspace data type parameter, the Path value can be passed to the tool using inline variable substitution such as %Path%\Out_%Name%.%Extension%.

    Parse Path with the Create Feature Class tool

Parameters

LabelExplanationData Type
Input Values

The input values to parse.

Any Value
Format Name, Extension and Workspace
(Optional)

Removes all reserved characters. Given the input value of C:\1Tool Data\InputFC.shp:

  • Path—The output will be the file path, for example, C:\1Tool Data.
  • Name—The output will be the file name, for example, InputFC.
  • Extension—The output will be the file extension, for example, shp.
  • Workspace Name—The output will be the workspace name, for example, _1Tool_Data.

Boolean

Derived Output

LabelExplanationData Type
Path

The workspace of the input.

Workspace
Name

The file name, excluding the extension.

String
Extension

The file extension.

String
Workspace Name

The name of the workspace.

String

Environments

This tool does not use any geoprocessing environments.

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics