# How can I validate if a view exist in the project folder with perspective

**URL:** <https://forum.inductiveautomation.com/t/how-can-i-validate-if-a-view-exist-in-the-project-folder-with-perspective/35088>\
**Category:** Ignition\
**Created:** [May 27, 2020, 3:37pm UTC](https://forum.inductiveautomation.com/t/how-can-i-validate-if-a-view-exist-in-the-project-folder-with-perspective/35088 "2020-05-27T15:37:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luc.martin](https://avatars.discourse-cdn.com/v4/letter/l/77aa72/32.png) [@luc.martin](https://forum.inductiveautomation.com/u/luc.martin)\
**Post date:** [May 27, 2020, 3:37pm UTC](https://forum.inductiveautomation.com/t/how-can-i-validate-if-a-view-exist-in-the-project-folder-with-perspective/35088/1 "2020-05-27T15:37:16Z")

</div>

Is ther a way to valide that a view exist?

Actually I use a script with hardcoded path, but I search a way to do that more efficially with binding path.

My script;  
path = “C:/Program Files/Inductive Automation/Ignition/data/projects/AMT/com.inductiveautomation.perspective/views/1-UDTS\AS0153\_TRIM\_PRESS/SETUP/Elems”

value = system.file.fileExists(path + “/Extras/ejector\_closed\_position”)  
return value

I have a button that I want to root to a specific view if the view exit.

Anyone have better solution for me?

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 27, 2020, 9:08pm UTC](https://forum.inductiveautomation.com/t/how-can-i-validate-if-a-view-exist-in-the-project-folder-with-perspective/35088/2 "2020-05-27T21:08:02Z")

</div>

You should be putting all of your code within preformatted text characters ``

```auto
This = some_code
If you_add:
       Tabs = 'they remain intact' 

```

---

<div class="post-metadata">

**Author:** ![luc.martin](https://avatars.discourse-cdn.com/v4/letter/l/77aa72/32.png) [@luc.martin](https://forum.inductiveautomation.com/u/luc.martin)\
**Post date:** [June 2, 2020, 6:51pm UTC](https://forum.inductiveautomation.com/t/how-can-i-validate-if-a-view-exist-in-the-project-folder-with-perspective/35088/3 "2020-06-02T18:51:42Z")

</div>

I don’t understand your explanation. How can I validate if a view exist in a specific folder of my project?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 2, 2020, 6:58pm UTC](https://forum.inductiveautomation.com/t/how-can-i-validate-if-a-view-exist-in-the-project-folder-with-perspective/35088/4 "2020-06-02T18:58:59Z")

</div>

He’s saying you should post your code by putting it between

```

```auto
my code here

```

```  
so that it gets formatted and we can read it better

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 2, 2020, 7:09pm UTC](https://forum.inductiveautomation.com/t/how-can-i-validate-if-a-view-exist-in-the-project-folder-with-perspective/35088/5 "2020-06-02T19:09:33Z")

</div>

From your post its hard to tell exactly what your script is, how it’s being called, if its inside a function, etc. However, I think it sounds like you just want a function that checks if a file exists? `system.file.fileExists` already does that. But if you ar einclined to make your own function, you can do

```auto
def fileExists(filePath):
    """
    Checks if a file exists.
    Args:
        filePath: str, file path to check
    Returns:
        boolean, true if file exists, false otherwise
    """
    import system.file
    return system.file.fileExists(filePath)

```

---

<div class="post-metadata">

**Author:** ![luc.martin](https://avatars.discourse-cdn.com/v4/letter/l/77aa72/32.png) [@luc.martin](https://forum.inductiveautomation.com/u/luc.martin)\
**Post date:** [June 2, 2020, 7:29pm UTC](https://forum.inductiveautomation.com/t/how-can-i-validate-if-a-view-exist-in-the-project-folder-with-perspective/35088/6 "2020-06-02T19:29:00Z")

</div>

I know that and I want to build my own function, but I don’t want to have to specified the local path of my perspective project manually. I search a way to be able to get the direct path to my perspective project folder.

```auto
def transform(self, value, quality, timestamp):
	"""
	self.view.custom_view_path = C:/Program Files/Inductive Automation/Ignition/data/projects/AMT/com.inductiveautomation.perspective/views/

    I search a way to get that path withaout having to declared it manually. How to get perspective view path of my project?
	"""
	viewPath = "1-UDTS/AS0153_TRIM_PRESS/SETUP/Elems/Extras/"
	fullPath = self.view.custom.views_path + viewPath
	tags = system.tag.browseTags(parentPath=value["items_path"])
	
	tags_dict = {}			
	for tag in tags:
		if value["mode_text"]=="install":
			if self.parent.custom.when==self.parent.custom.constants_setup_item_when.always or self.parent.custom.when==self.parent.custom.constants_setup_item_when.install_only:
				add_need=True
			else:
				add_need=self.view.custom.show_all
		elif value["mode_text"]=="uninstall":
			if self.parent.custom.when==self.parent.custom.constants_setup_item_when.always or self.parent.custom.when==self.parent.custom.constants_setup_item_when.uninstall_only:
				add_need=True
			else:
				add_need=self.view.custom.show_all		
		else:
			add_need=self.view.custom.show_all
						
		if add_need:
			tags_dict[tag.fullPath] = system.tag.read(tag.fullPath + "/preset/sort_order").value
		
	tags_sorted = sorted(tags_dict.items(), key=lambda x: x[1])
	
	instances = []
	for k, v in list(tags_sorted):
			my_dict={}
			my_dict["instanceStyle"]={}
			my_dict["instanceStyle"]["classes"]=""
			my_dict["instancePosition"]={}
			my_dict["title"] = "tp_setup_" + k.rsplit("/",1)[1] + "_title"
			my_dict["description"] = "tp_setup_" + k.rsplit("/",1)[1] + "_" + value["mode_text"]
			my_dict["item_path"] = k
			my_dict["popUp"]=self.view.custom.popUp
			my_dict["show_all"]=self.view.custom.show_all
			my_dict["clic_enabled"]=self.view.custom.clic_enabled
			my_dict["path"]=self.view.params.path
			my_dict["access_role"]=self.view.params.access_role
			my_dict["needs_type"]=value["needs_type"]
			my_dict["mode_text"]=value["mode_text"]
			
			if system.file.fileExists(fullPath + k.rsplit("/",1)[1] + "_" + value["mode_text"]):
				my_dict["custom_view_exist"] = True
				my_dict["custom_view_name"] = viewPath + k.rsplit("/",1)[1] + "_" + value["mode_text"]
			else:
				my_dict["custom_view_exist"] = False
				my_dict["custom_view_name"] = None
			instances.append(my_dict)
	
	return instances

```
