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.
Usage
This tool is intended for use in ModelBuilder and not in Python scripting.
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:
Parse Result Path C:\1Tool Data Name City Roads Extension shp Workspace Name 1Tool Data If the Format Name, Extension and Workspace parameter is checked, the path above will be parsed into the following outputs:
Parse Result Path C:\1Tool Data Name City_Roads Extension shp 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
- To get the name City Roads
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%.
Syntax
ParsePathExt(in_data_element, {format})
Parameter | Explanation | Data Type |
in_data_element | The input values to parse. | Any Value |
format (Optional) | Removes all reserved characters. Given the input value of C:\1Tool Data\InputFC.shp:
| Boolean |
Derived Output
Name | Explanation | Data Type |
path | The workspace of the input. | Workspace |
name | The file name, excluding the extension. | String |
extension_type | The file extension. | String |
workspace_name | The name of the workspace. | String |
Environments
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes