# Find paths of all tags in default provider

**URL:** <https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293>\
**Category:** Module Development\
**Tags:** ignition79\
**Created:** [May 24, 2019, 1:04pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293 "2019-05-24T13:04:12Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![fyousuf](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@fyousuf](https://forum.inductiveautomation.com/u/fyousuf)\
**Post date:** [May 24, 2019, 1:04pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293/1 "2019-05-24T13:04:12Z")

</div>

I’m attempting to read all tags in the gateway from the default provider and copy those to a database. I’m able to do so if I hard-code each tagpath using TagPathParser.parse(“string path”) , but is what is the way to do so without hard-coding? If I do:

```auto
TagPath path = TagPathParser.parse("[default]");
List<Tag>tag=browse(path);

```

Is there a way to get the tagpaths of the list of tags?

Any help is appreciated.

---

<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:** [May 24, 2019, 1:15pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293/2 "2019-05-24T13:15:43Z")

</div>

```auto
def getAllTags(tagPath):
	appRoot = tagPath
	browseTagArray = system.tag.browseTags(parentPath="[default]"+appRoot,recursive=True)
	tagDataset = []
	tagHeaders = ['name', 'fullPath', 'type', 'dataType']
	for browseTag in browseTagArray:
		if not browseTag.isFolder():
			tagDataset.append([browseTag.name, browseTag.fullPath, browseTag.type, browseTag.dataType]);
	return system.dataset.toDataSet(tagHeaders, tagDataset)

```

This function will take a passed root folder and parse ALL the tags below that and return it as a dataset.  
Be careful if you have a very large tag database, this could take a long time.

---

<div class="post-metadata">

**Author:** ![fyousuf](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@fyousuf](https://forum.inductiveautomation.com/u/fyousuf)\
**Post date:** [May 24, 2019, 1:47pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293/3 "2019-05-24T13:47:09Z")

</div>

I assume I’ll need to download jython, then (sorry, I’m pretty new to java). Thank you, I’ll try this.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 24, 2019, 1:49pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293/4 "2019-05-24T13:49:31Z")

</div>

I don’t think he realized this was a module SDK question (this _is_ a module SDK question, right?)

---

<div class="post-metadata">

**Author:** ![fyousuf](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@fyousuf](https://forum.inductiveautomation.com/u/fyousuf)\
**Post date:** [May 24, 2019, 1:50pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293/5 "2019-05-24T13:50:45Z")

</div>

Yes, it is.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 24, 2019, 1:52pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293/6 "2019-05-24T13:52:43Z")

</div>

You’ll want to use `TagManager#browseAsync`, starting with the TagPath you built to the provider, and then continuing to browse recursively for all the results you get at each level.

---

<div class="post-metadata">

**Author:** ![fyousuf](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@fyousuf](https://forum.inductiveautomation.com/u/fyousuf)\
**Post date:** [May 24, 2019, 7:25pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293/7 "2019-05-24T19:25:17Z")

</div>

So I’m using the 7.9 API and I still haven’t been able to access the tags. I assume my problem is that my nextNode string in getChildPath is empty? The project compiles but there’s no change to the database.

```auto
 public void findTags() throws IOException {
    	String nextNode="";
    	dpath = TagPathParser.parse("[default]");
    	tag = context.getTagManager().getTagProvider("[default]").browse(dpath);
    	temppath=dpath;
    	while (tag.isEmpty()==true) {
			temppath = temppath.getChildPath(nextNode);
			tag = context.getTagManager().getTagProvider("[default]").browse(temppath);
    	}
    	String tagname=tag.get(0).getName();
    	TagPath name = TagPathParser.parse(tagname);
    	TagPath parent = name.getParentPath();
    	TagPath reversepath[]=new TagPath[]{};
    	TagPath temparr[]=new TagPath[] {};
    	while(parent!=dpath) {
    		TagPath pathslash = BasicTagPath.append(parent, TagPathParser.parse("/"));
    		temparr[0]= pathslash;
    		parent=parent.getParentPath();
    		reversepath=ArrayUtils.addAll(reversepath, temparr);
    	}
    	for (int i=((reversepath.length)-1);i>=0;i--) {
    		wholepath= BasicTagPath.append(wholepath,reversepath[i]);
    	}
    	wholepath = BasicTagPath.append(dpath, wholepath);
    	wholepath=BasicTagPath.append(wholepath, name);
    	readingTag();
    }
    public void readingTag() throws IOException{
		listpaths.add(wholepath);
		
		TagListener listener = new TagListener(wholepath) {
		};
		
		context.getTagManager().subscribe(wholepath, listener);
		tags= context.getTagManager().read(listpaths);
		tagvalue = (int)tags.get(0).getValue();
		tagqual = tags.get(0).getQuality();
		Date df = tags.get(0).getTimestamp();
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss", Locale.getDefault());
		tagdate = dateFormat.format(df);
		tagpath = listpaths.get(0);
		datacopy(tagpath,tagvalue,tagqual,tagdate);
	}
	public void datacopy(TagPath tp,int value, Quality qual, String date) {
		try {
			dbconnection = GatewayHook.context.getDatasourceManager().getConnection("ModTest");//connect to db
		} catch (SQLException e) {
			logger.fatal("Database connection failed.",e);
		}
		String query = String.format("INSERT INTO [ModTAGS].[dbo].[ModuleTags] (TagName, TagValue, TagQuality, TagTimeStamp) VALUES ('%s',%d,'%s','%s')",tp,value,qual,date);//insert tag list
		try {
			dbconnection.runPrepQuery(query);//insert tag list
		} catch (SQLException e) {
			logger.fatal("SQL copy fail",e);
			
		}
	}

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 24, 2019, 7:28pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293/8 "2019-05-24T19:28:14Z")

</div>

I’d start by adding a bunch of logging to let you know how far you’re getting and if you’re getting the data you expect at each step.

---

<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:** [May 24, 2019, 8:15pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293/9 "2019-05-24T20:15:40Z")

</div>

Ahh man, sorry about that, I browse using latest posts, not by category. 😊

---

<div class="post-metadata">

**Author:** ![fyousuf](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@fyousuf](https://forum.inductiveautomation.com/u/fyousuf)\
**Post date:** [May 24, 2019, 8:21pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293/10 "2019-05-24T20:21:01Z")

</div>

Not a problem!

---

<div class="post-metadata">

**Author:** ![fyousuf](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@fyousuf](https://forum.inductiveautomation.com/u/fyousuf)\
**Post date:** [May 28, 2019, 1:26pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293/11 "2019-05-28T13:26:47Z")

</div>

It appears the problem is with my .getChildPath(nextNode) statement since no it returns the name of the tag provider ("[default]"):

```auto
TagPath dPath=TagPathParser.parse("[default]");
TagPath cPath=dPath.getChildPath("[default]");
nextNode = cPath.getItemName();
TagPath cPath2 = cPath.getChildPath(nextNode);
String sPath = cPath2.getItemName();

```

sPath (and cPath2) appear to be “[default]” and I can’t get the folder below it. What am I missing in the getChildPath parameters?

---

<div class="post-metadata">

**Author:** ![fyousuf](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@fyousuf](https://forum.inductiveautomation.com/u/fyousuf)\
**Post date:** [May 29, 2019, 2:59pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293/12 "2019-05-29T14:59:21Z")

</div>

In case anyone has time, I’m trying to find the the path to a tag that may be nested inside a folder:  
[default]/FolderName/Tag. However, getChildPath only returns the nextNode string parameter as a tagpath, not the child of that string. Is getChildPath the right way to go about this?

```auto
TagPath dPath=TagPathParser.parse("[default]");
TagPath cPath=dPath.getChildPath("[default]");
nextNode = cPath.getItemName();
TagPath cPath2 = cPath.getChildPath(nextNode);
String sPath = cPath2.getItemName();

```

sPath (and cPath2) appear to be “[default]” and I can’t get the folder below it.

---

<div class="post-metadata">

**Author:** ![fyousuf](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@fyousuf](https://forum.inductiveautomation.com/u/fyousuf)\
**Post date:** [May 29, 2019, 4:57pm UTC](https://forum.inductiveautomation.com/t/find-paths-of-all-tags-in-default-provider/25293/13 "2019-05-29T16:57:09Z")

</div>

Figured it out! I assumed using `browse("[default]")` returned an empty collection, but a folder is treated as a tag, so the name of the first folder is returned.

```auto
tag = context.getTagManager().getTagProvider("default").browse(dpath);
//tag.get(0) is TestPath (a folder in the tagprovider)

```
