I’m looking for the correct method to programmatically rename a tag folder. My attempt succeeds in creating a copy of the original folder, in the same location having the desired new name. However, the original folder remains as well. I’m using the system.tag.configure() function to perform the operation but am apparently using some flawed logic. This is under Ignition v8.1.3.
try something like this:
tags = system.tag.browse('[Default]old folder name').getResults() paths = [str(tag['fullPath']) for tag in tags] system.tag.move(paths, '[Default]new folder name', 'a') # then delete the old folder if you want.
**I had to edit because my solution was not correct. it moved the entire folder into a new folder. This solution reads the tags names in the older folder, and moves them into a new folder. The old folder will need to be deleted if that is what you want to do.
So there is no way to just rename the folder without essentially duplicating the old folder and then deleting the old folder?
I am not sure exactly if there is a better way than the way that I provided. But the way I suggested does not create a copy of the old folder, it moves the contents of the old folder into a new folder, leaving the old folder empty. Then you can delete the old folder if you want. Otherwise, you could use system.tag.getConfiguration on the parent folder of your target folder, and rename the folder in the result dictionary, then write it back using system.tag.configure. That method has the potential to be very, very slow because you will have to recursively read the entire contents of the parent folder.
Your second suggestion was the path I was trying to use. It did what I wanted but left the original folder and its contents after replicating it to the new folder name. I was hoping for a cleaner solution that didn’t leave the old folder and contents behind. Thank you for the responses.
I do think that the following code will accomplish exactly what you want, however. It will move the contents to the new folder, leaving the old folder completely empty, then delete the empty old folder. So it does leave the old folder behind, but the contents are moved into the new folder. Then the old folder is deleted, so effectively, the tags had their folder’s name changed.
tags = system.tag.browse('[Default]old folder name').getResults() paths = [str(tag['fullPath']) for tag in tags] system.tag.move(paths, '[Default]new folder name', 'a') system.tag.deleteTags('[Default]old folder name')
That’s the path I’m headed down. Thank you again.