# Create filepath String with '\\R'

**URL:** <https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157>\
**Category:** Ignition\
**Created:** [June 24, 2021, 2:00pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157 "2021-06-24T14:00:44Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![jacque\_trahan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jacque_trahan/32/58886_2.png) [@jacque\_trahan](https://forum.inductiveautomation.com/u/jacque_trahan)\
**Post date:** [March 10, 2023, 2:55pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/21 "2023-03-10T14:55:47Z")

</div>

Great info here. I also go this work as follows:

`filePath = r"C:\Users\user\Documents\Project\MyFile.csv"`

The r in front [denotes a raw, (almost) un-escaped string](https://discuss.python.org/t/what-does-r-define-in-file-path/3646) Which is allowed in ignition and jython(python2.7)

That said, I wanted to add a component to my perspective view. And if I try to use some thing like this

`csvPath = rstr(self.getSibling("FilePath").props.text)`  
or do the above without the r then try to update it as follows  
`csvPath = rcsvPath`

I will get the following similar errors for both examples:

> NameError: global name 'rstr' is not defined

With that said. I tried a few different ways like above, but can not seem to figure out a way to do this through a component. I was curious is this possible at all, or will we just need to change the file path manually in the code if we ever need to change it?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 10, 2023, 4:44pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/22 "2023-03-10T16:44:52Z")

</div>

You can only create raw literals as in your first example. Try using repr().

```auto
csvPath = repr(self.getSibling("FilePath").props.text)

```

---

<div class="post-metadata">

**Author:** ![jacque\_trahan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jacque_trahan/32/58886_2.png) [@jacque\_trahan](https://forum.inductiveautomation.com/u/jacque_trahan)\
**Post date:** [March 10, 2023, 6:03pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/23 "2023-03-10T18:03:21Z")

</div>

Unfortunately that does not work as well.

I get this error with this code:  
**Code:**

```auto
csvPath = repr(self.getSibling("TextField").props.text)

```

**Error:**

> IOError: [Errno 2] No such file or directory: 'u'"C:\\Users\\user\\Documents\\Project\\IgnitionFiles\\Work\\Alarms\\myfile.csv"''

Also tried this:  
**Code:**

```auto
csvPath = eval(repr(self.getSibling("TextField").props.text))

```

**Error:**

> IOError: [Errno 2] No such file or directory: u'"C:\Users\user\Documents\Project\IgnitionFiles\Work\Alarms\myfile.csv"'

---

<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:** [March 10, 2023, 6:35pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/24 "2023-03-10T18:35:40Z")

</div>

You likely don't need any of these things.

If you've got a path that _looks_ correct (visually, in the text field) then you should be able to pass it directly to the file function you want. You only need backslash escaping, raw strings, etc, when you are _defining the string in your code_. A string is a string is a string - all hints like the `r` prefix do is tell the local parser that the next encountered string should be parsed as a raw string - after parsing, it's a string like any other, no matter what values it contains.

---

<div class="post-metadata">

**Author:** ![jacque\_trahan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jacque_trahan/32/58886_2.png) [@jacque\_trahan](https://forum.inductiveautomation.com/u/jacque_trahan)\
**Post date:** [March 10, 2023, 6:42pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/25 "2023-03-10T18:42:15Z")

</div>

Hmmm not sure why it doesn't take effect then.

I tried it just with the component, no extra functions included, and get this error:

> IOError: [Errno 2] No such file or directory: u'"C:\Users\User\Documents\Project\IgnitionFiles\Work\Alarms\myfile.csv"'

I think I'll leave it hard coded for now using the `r"C:\FilePath.csv.` It works fine but would have been nice for others to use a components with.

---

<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:** [March 10, 2023, 7:05pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/26 "2023-03-10T19:05:15Z")

</div>

If you're in a Perspective context, keep in mind the script is running as whatever the Gateway service user is. Windows might be "lying" to the service and saying there's no such file because of permissions.

---

<div class="post-metadata">

**Author:** ![jacque\_trahan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jacque_trahan/32/58886_2.png) [@jacque\_trahan](https://forum.inductiveautomation.com/u/jacque_trahan)\
**Post date:** [March 10, 2023, 7:21pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/27 "2023-03-10T19:21:19Z")

</div>

That would make sense. Thank you so much!

**EDIT**

I got this to work but not in the original way I was trying to do it.

The way I was try was to use that component value with the csv module syntax open with(path,"r") as f:  
Trying to do it like that I would get errors.

BUT

If you use that component value and then use it in an Ignition function it works just fine. Wanted to export a dataset to a CSV file and the file path was put into a component(No quotes) and it worked just fine.

[Previous page](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157.md?page=1)
