# Browse tags printing folder

**URL:** <https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498>\
**Category:** Ignition\
**Tags:** ignition78, vision, scripting\
**Created:** [June 8, 2022, 3:39pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498 "2022-06-08T15:39:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 8, 2022, 3:39pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/1 "2022-06-08T15:39:46Z")

</div>

Hello, I am trying to setup a client project script (let me know if gateway would be better). To reset nightly tags. It’s a decent amount of tags so I’d like to loop it.

Ideally, I loop all the the tags under a folder, and write 0 to all of them at midnight using some sort of if time = midnight checked hourly.

I can loop using below code:

```auto
tags = system.tag.browseTags(parentPath="System1/Efficiency", recursive=True)
for tag in tags:
    print tag.path

```

But my issue is it prints the folder names see below: Should I exclude them/how can I?

![folderresults](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/a/7aa96f8903093b482261d6ebd74eeae8fb9b53d9.png)  
 ![folderstruct](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/e/ee6454c582ca9c65ffc69d5c1e74e7e3a9828bb9.png)

---

<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:** [June 8, 2022, 3:48pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/2 "2022-06-08T15:48:12Z")

</div>

Use `.isFolder()` to filter out folders, and also turn off recursion if you don’t want tags that are included in the folders.

```python
tags = system.tag.browseTags(parentPath="System1/Efficiency", recursive = False)
for tag in tags:
    if not tag.isFolder():
       print tag.path

```

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 8, 2022, 4:04pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/3 "2022-06-08T16:04:41Z")

</div>

@lrose thank you! I want tag path because i want to reset them all all at midnight with something like the full code below:

```auto
# Grabs current Date and Time
getDateTime = system.date.now()
# Returns current hour in a 0-23 format
getHour = system.date.format(today, "H")
# Creat array to store tag paths
resetPaths = []
# Checks if time is Midnight
if getHour == 0:
# Gets all tags in folder sub structure and writes to an array
	tags = system.tag.browseTags(parentPath="System1/Efficiency", recursive = True)
	for tag in tags:
    if not tag.isFolder():
    	# Wrties tag path to array
       	resetPaths.append (tag.path)
       	# Writes a 0 to clear all tags in array
		system.tag.writeAll(resetPaths,0)

```

And I’ll run it in a timer script to check once an hour. Just not sure if client or gateway timer script would be better?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 8, 2022, 4:21pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/4 "2022-06-08T16:21:25Z")

</div>

Definitely gateway timer script. A client timer script will 1. only work if there’s at least one client running, and 2. be run _by each client you have open_.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 8, 2022, 4:41pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/5 "2022-06-08T16:41:14Z")

</div>

Quick back track @paul-griffith and @lrose I’m getting the below error with the above code:  
 ![error](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/c/2ca6e1272d0fb3eeea19c67af64bc385bbd613a0.png)

---

<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:** [June 8, 2022, 5:02pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/6 "2022-06-08T17:02:56Z")

</div>

All of the indentation must match. Meaning you can’t mix and match “spaces” and “tabs”.

When I typed in the script I used spaces, so you probably just need to fix that.

---

<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:** [June 8, 2022, 5:06pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/7 "2022-06-08T17:06:47Z")

</div>

In your script the `system.tag.writeAll()` should be outside of the for loop. You only want to call it once. You will also need to provide it with a list of values, that matches list of paths.

```auto
# Grabs current Date and Time
getDateTime = system.date.now()
# Returns current hour in a 0-23 format
getHour = system.date.format(today, "H")
# Creat array to store tag paths
resetPaths = []
# Checks if time is Midnight
if getHour == 0:
# Gets all tags in folder sub structure and writes to an array
	tags = system.tag.browseTags(parentPath="System1/Efficiency", recursive = True)
	for tag in tags:
        if not tag.isFolder():
    	    # Wrties tag path to array
       	    resetPaths.append (tag.path)
    # Writes a 0 to clear all tags in array
    system.tag.writeAll(resetPaths,[0] * len(resetPaths))

```

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 8, 2022, 5:59pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/9 "2022-06-08T17:59:17Z")

</div>

Thank you, I went line by line and found it.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 8, 2022, 6:12pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/10 "2022-06-08T18:12:17Z")

</div>

@lrose as I ponder this could I remove the 0 from the array to set them ‘blank’ I just used 0 because I assumed a value had to be written.

---

<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:** [June 8, 2022, 6:18pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/11 "2022-06-08T18:18:34Z")

</div>

You could potentially use `None` if that is what you mean. I suppose it just depends on the types of the tags you are writing. For integers `None` is essentially `0`.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 8, 2022, 6:20pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/12 "2022-06-08T18:20:35Z")

</div>

fair enough, i guess a 0 works more universally per say.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 9, 2022, 1:08pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/13 "2022-06-09T13:08:03Z")

</div>

@lrose Hey so I cam back today to no tags reset. It’s in a gateway event timer script set to 3,600,000 fixed rate.

I tried manually running script in script console replacing 0 with current hour, but no tags got cleared.

I tried moving the reset array to a var. but still no luck. Not sure why it’s not resetting anything.

Also there are only string and integer type tags. I’d assume the writing a 0 would work. I don’t get any errors.

---

<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:** [June 9, 2022, 2:35pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/14 "2022-06-09T14:35:52Z")

</div>

Do you have any logging in the script? Do you see any errors in the Wrapper Logs? What are the types of the tags you are resetting and are they all the same type?

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 9, 2022, 2:51pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/15 "2022-06-09T14:51:21Z")

</div>

@lrose No logging in the script. Nothing in the console logs which i believe is the same as the wrapper log.

some are string and integers  
some are opc, memory and expression

I did try adding some logging at the bottom. Not seeing anything. Maybe I’m doing it wrong lol idk.

I appreciate the help.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 9, 2022, 3:07pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/16 "2022-06-09T15:07:43Z")

</div>

`0` is not the same as `""` is not the same as `null/None` - you probably have to write the correct initial value type for the tag’s type. You could read the data type and have a simple dictionary of tag types : initial tag values.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 9, 2022, 3:37pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/17 "2022-06-09T15:37:47Z")

</div>

@paul-griffith I tired this code below with no avail:

```auto
# Grabs current Date and Time
getDateTime = system.date.now()
# Returns current hour in a 0-23 format
getHour = system.date.format(getDateTime, "H")
# Creates array to store tag paths
intPaths = []
stringPaths = []
# Checks if time is Midnight
if getHour == 7:
# Gets all tags in folder sub structure and writes to an array
    tags = system.tag.browseTags(parentPath="System1/Efficiency", recursive = True)
    for tag in tags:
        if not tag.isFolder():
            if tag.dataType == Int4:
    	    # Wrties tag path to array
       	        intPaths.append (tag.path)
       	    elif tag.dataType == String:
       	        stringPaths.append (tag.path)
    # Creates array for reset values
    resetInt = [None] * len(intPaths)
    resetStr = [""] * len(stringPaths)
    # Writes a 0 to clear all tags in array
    system.tag.writeAll(intPaths,resetInt)
    system.tag.writeAll(stringPaths,resetStr)

```

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 9, 2022, 3:55pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/18 "2022-06-09T15:55:56Z")

</div>

I think it has something to do with the for loop. because right now I can not print tag paths right under for tag in tags.

When I delete the code above the for loop and remove indents i can print tag.path to the console. but not with the above code.

---

<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:** [June 9, 2022, 4:03pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/19 "2022-06-09T16:03:50Z")

</div>

> [@andrews](#):
>
> @lrose No logging in the script. Nothing in the console logs which i believe is the same as the wrapper log.

The console log is not the same as the wrapper log.

> [@Event Configuration Print Out to debug](https://forum.inductiveautomation.com/t/event-configuration-print-out-to-debug/60091/5):
>
> It’s complicated slight_smile Starting from most local to least… In the script console, print will log directly to the output buffer on the right hand side. system.util.getLogger() will log to the named ‘Output Console’ Designer window. Bonus: A script invoked from here using system.util.invokeAsync will print to the regular output console, not the buffer on the right hand side. Anywhere else in the designer (except Perspective), print and system.util.getLogger will log to the ‘Out…

Here is a small example of using a logger.

> [@Troubleshooting tag event script suggestions?](https://forum.inductiveautomation.com/t/troubleshooting-tag-event-script-suggestions/26560/2):
>
> If the tag diagnostics on the tags are not showing any error, then, your best bet is to implement a logger with a try…except structure. Something like: import java.lang.Exception logger = system.util.getLogger("yourLoggerName") try: #script to attempt except: java.lang.Exception, e: logger.warn("An error occurred" , e) except Exception, e: logger.warnf("An error occurred: %s",e)@pturmel has a PythonAsJavaException class in his [later.py](https://www.automation-pros.com/ignition/later.py) which will allow for more detail in th…

This:

```auto
if tag.dataType == Int4:

```

Doesn't do what you think it does. `Int4` is a type, `tag.dataType` ~~returns a string value~~ returns a `com.inductiveautomation.ignition.common.sqltags.model.types.DataType`. The two can never be equivalent.

~~ 

```auto
if tag.dataType == 'Int4':
    #do something
elif tag.dataType == 'String':
   #do something else

```

 ~~~~I would also use 0 for the default value for Integers. Also, instead of calling writeAll twice, combine the lists first and then call writeAll~~~~ ``` paths = intPaths + stringPaths values = resetInt + resetStr system.tag.writeAll(paths,values) ```~~

Edit: See @paul-griffith's code below

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 9, 2022, 4:15pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/20 "2022-06-09T16:15:05Z")

</div>

```python
from com.inductiveautomation.ignition.common import TypeUtilities

# Grabs current Date and Time
getDateTime = system.date.now()
# Returns current hour in a 0-23 format
getHour = system.date.getHour24(getDateTime)
# Creates list to store tag paths
paths = []

# Checks if time is Midnight
if getHour == 7:
	# Gets all tags in folder sub structure and writes to an array
    tags = system.tag.browseTags(parentPath="folder", recursive = True)
    for tag in tags:
        if not tag.isFolder():
        	paths.append((tag.path, TypeUtilities.getInitValueForClass(tag.dataType.javaType)))
        	
    paths, values = list(zip(*paths))
    system.tag.writeAll(paths, values)

```

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [June 9, 2022, 4:31pm UTC](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498/21 "2022-06-09T16:31:22Z")

</div>

@paul-griffith that worked like a charm! Now if I can just learn from your code and understand what you did. lol. If you could explain a little more in depth how your code works I’d be very appreciative.

There are just a few tags I’ll need to work on including that im sure are somewhere else. maybe write that tag to another one in a subfolder so this works 100% for me. But that should be easy.

I’d just really like to do some googling and understand it so i’m capable of doing it in the future.

[Next page](https://forum.inductiveautomation.com/t/browse-tags-printing-folder/60498.md?page=2)
