# Script get parent path including root

**URL:** <https://forum.inductiveautomation.com/t/script-get-parent-path-including-root/83446>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [December 21, 2023, 8:42pm UTC](https://forum.inductiveautomation.com/t/script-get-parent-path-including-root/83446 "2023-12-21T20:42:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [December 21, 2023, 8:42pm UTC](https://forum.inductiveautomation.com/t/script-get-parent-path-including-root/83446/1 "2023-12-21T20:42:14Z")

</div>

I have a list of tags that I want to determine their parent...  
For the first two examples, I usually use something like this:

```auto
tag.replace('\\','/')

```

[MyTP]first/second/third, parent = [MyTP]first/second  
[MyTP]first/second, parent = [MyTP]first

But, that doesn't work for the root. Does anyone have a nifty way to get a parent including the root?  
[MyTP]first, parent = [MyTP]

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 21, 2023, 9:11pm UTC](https://forum.inductiveautomation.com/t/script-get-parent-path-including-root/83446/2 "2023-12-21T21:11:10Z")

</div>

Might be easiest to use the `os.path` module  
[10.1. os.path — Common pathname manipulations — Python 2.7.18 documentation](https://docs.python.org/2.7/library/os.path.html#module-os.path)

```auto
from os import path
print path.dirname('[MyTP]first/second/third')

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 21, 2023, 9:20pm UTC](https://forum.inductiveautomation.com/t/script-get-parent-path-including-root/83446/3 "2023-12-21T21:20:08Z")

</div>

Use the [TagPathParser](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.36-rc2/com/inductiveautomation/ignition/common/tags/paths/parser/TagPathParser.html) to parse the string into a [TagPath](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.36-rc2/com/inductiveautomation/ignition/common/tags/model/TagPath.html).

```auto
from com.inductiveautomation.ignition.common.tags.paths.parser import TagPathParser

path = "[MyTP]first/second/third"
tagPath = TagPathParser.parse(path)
print 'Provider :=', tagPath.source, 'ParentPath :=', tagPath.parentPath

```

Output:

```auto
>>> 
Provider := MyTP ParentPath := [MyTP]first/second
>>> 

```

EDIT: I think that I didn't fully answer your question, in your case where the path supplied is `'[MyTP]First'` then the output is:

```auto
>>> 
Provider := MyTP ParentPath := [MyTP]
>>> 

```

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [December 21, 2023, 9:38pm UTC](https://forum.inductiveautomation.com/t/script-get-parent-path-including-root/83446/4 "2023-12-21T21:38:23Z")

</div>

Perfect, a much cleaner solution.
