# Passing current folder name into a Python script

**URL:** <https://forum.inductiveautomation.com/t/passing-current-folder-name-into-a-python-script/17282>\
**Category:** Ignition\
**Created:** [March 8, 2018, 6:28pm UTC](https://forum.inductiveautomation.com/t/passing-current-folder-name-into-a-python-script/17282 "2018-03-08T18:28:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffkrol](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeffkrol/32/3339_2.png) [@jeffkrol](https://forum.inductiveautomation.com/u/jeffkrol)\
**Post date:** [March 8, 2018, 6:28pm UTC](https://forum.inductiveautomation.com/t/passing-current-folder-name-into-a-python-script/17282/1 "2018-03-08T18:28:35Z")

</div>

Howdy,

I’ve written my own script that I’m calling via expression tag that returns how many medium-critical alarms are currently unacknowledged. The script works very well, but I’m trying to dynamically pass in the current folder name. I have hundreds of folders to put this expression tag into, so I’m looking for any sort of time saving features I can.

This is the expression that I am calling:

`runScript("shared.alarmsMisc.alarmActiveInFolder('CRAH/CIDF_2')",3000)`

---

<div class="post-metadata">

**Author:** ![jeffkrol](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeffkrol/32/3339_2.png) [@jeffkrol](https://forum.inductiveautomation.com/u/jeffkrol)\
**Post date:** [March 8, 2018, 8:19pm UTC](https://forum.inductiveautomation.com/t/passing-current-folder-name-into-a-python-script/17282/2 "2018-03-08T20:19:10Z")

</div>

As a workaround I am using a string memory tag that has the containing folder hard coded. If any of y’all can find me a better solution, I can switch the memory tag to an expression tag but this will work for now…

`runScript("shared.alarmsMisc.alarmUnackedInFolder('"+{[.]_AlarmFolderName}+"')",3000)`

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [March 8, 2018, 8:34pm UTC](https://forum.inductiveautomation.com/t/passing-current-folder-name-into-a-python-script/17282/3 "2018-03-08T20:34:17Z")

</div>

What we do is create Integer expression tags in each tag area folder and then use  
toInt(runScript(“len(system.alarm.queryStatus(state=[‘ActiveUnacked’],source=[‘_PLAS/Board/_’]))”,2000))

This counts the ActiveUnacked alarms in that folder and sets the tag value to the number.  
You can then create one for ActiveAcked as well.

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [March 8, 2018, 9:01pm UTC](https://forum.inductiveautomation.com/t/passing-current-folder-name-into-a-python-script/17282/4 "2018-03-08T21:01:14Z")

</div>

So you’d like to automate the part where “CRAH/CIDF\_2” gets typed in?

You could simply wrap that expression tag in a UDT (FolderAlarmCounter UDT).  
Then in your existing expression tag which is now within a UDT instance, use:

`split("{PathToParentFolder}",'/')[0]`

To get the folder name.

---

<div class="post-metadata">

**Author:** ![jeffkrol](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeffkrol/32/3339_2.png) [@jeffkrol](https://forum.inductiveautomation.com/u/jeffkrol)\
**Post date:** [March 8, 2018, 9:25pm UTC](https://forum.inductiveautomation.com/t/passing-current-folder-name-into-a-python-script/17282/5 "2018-03-08T21:25:18Z")

</div>

MMaynard,

Thanks for the reply. That’s more or less what I am trying to do, but I want the source parameter to be dynamic. My custom scripts are calling ‘system.alarm.queryStatus’ with some code wrapped around it. I wrote a custom script because I might need to modify the parameters to ‘system.alarm.queryStatus’ and I have hundreds of calls to it.

Thanks again.

---

<div class="post-metadata">

**Author:** ![jeffkrol](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeffkrol/32/3339_2.png) [@jeffkrol](https://forum.inductiveautomation.com/u/jeffkrol)\
**Post date:** [March 8, 2018, 9:27pm UTC](https://forum.inductiveautomation.com/t/passing-current-folder-name-into-a-python-script/17282/6 "2018-03-08T21:27:01Z")

</div>

bfuson,

That seems like a clever solution. I had thought about solving this with UDTs, but didn’t investigate much further. I think I might have to try this out later. I’m resorting to hard coding the path for now, but in a separate memory tag so I can modify it later.

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [March 8, 2018, 9:42pm UTC](https://forum.inductiveautomation.com/t/passing-current-folder-name-into-a-python-script/17282/7 "2018-03-08T21:42:17Z")

</div>

If you really need to put your expression tag into hundreds of folders, I think this UDT ‘trick’ is the way to go.  
It keeps you from needing to specify the folder path at all. You simply make a new UDT instance in the folder and you’re done.

---

<div class="post-metadata">

**Author:** ![jeffkrol](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeffkrol/32/3339_2.png) [@jeffkrol](https://forum.inductiveautomation.com/u/jeffkrol)\
**Post date:** [March 8, 2018, 9:53pm UTC](https://forum.inductiveautomation.com/t/passing-current-folder-name-into-a-python-script/17282/8 "2018-03-08T21:53:18Z")

</div>

bfuson,

While you were writing up that post suggesting I use UDTs, I finally just say what the heck and went for it. I came back to post just that and I saw this post. You’re right that the best way to solve this is with UDTs. I’m literally just copying and pasting the one UDT instance into all of my folders now. Now while I marked your previous answer as the solution, I did have to make a small modification to your code because it was causing problems with subfolders. Here’s what I came up with for that string expression that returns the same string as when you right click on a device folder and select “Copy Tag Path”:

```auto
replace("{PathToParentFolder}","/"+"{InstanceName}","")

```
