# 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:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [June 24, 2021, 2:00pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/1 "2021-06-24T14:00:44Z")

</div>

I am trying to create a dynamic file path by creating a string for the file path. To test I simply created a label and want to make sure I have the formatting correct but I keep getting errors related to \R and \W being in the string.

The filepath I am trying to create is:  
C:\Recipe In\WG10-CSV.csv.  
I am going to add a dynamic value after Recipe In.

I have tried creating the string by separating the \ in the expression but no luck. I keep getting an error. How would I go about creating this filepath String?

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [June 24, 2021, 2:13pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/2 "2021-06-24T14:13:23Z")

</div>

change \ to / idk

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [June 24, 2021, 2:13pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/3 "2021-06-24T14:13:57Z")

</div>

Are you creating this filepath in a script? If so, double backslashes will work. In some cases forward slashes also work.

```auto
import csv
with open("C:\\Recipe In\\WG10-CSV.csv") as wg10:
    csvLines = csv.reader(wg10)
    for line in csvLines:
        # do some stuff
        pass

```

OR

```auto
import csv
with open("C:/Recipe In/WG10-CSV.csv") as wg10:
    csvLines = csv.reader(wg10)
    for line in csvLines:
        # do some stuff
        pass

```

The reason this is a problem for you is that \ is the escape character for python strings. `\n` is how you represent a newline, `\t` is tab. There are many others.

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [June 24, 2021, 2:20pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/4 "2021-06-24T14:20:00Z")

</div>

I did figure that about the \r and \w. Would the path still work if the the slashes are doubled and backwards?

I am trying to create the filepath in a string. I have the code below but that doesn’t seem to work either. I want filepath to be a string that I feed into the fileExists function. Getting an error with that as well.

```auto
		filepath = 'C:\Recipe In\BT{}\WG10-CSV.csv'.format(furnace_brass_tag_num)).value
		logger.info(toStr(filepath))
		if system.file.fileExists(toStr(filepath)):
# if system.file.fileExists("C:\Recipe In\WG10-CSV.csv"):

```

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [June 24, 2021, 2:28pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/5 "2021-06-24T14:28:46Z")

</div>

format is pyhton 3…

Try:  
`filepath = 'C:\\Recipe In\\BT%s\\WG10-CSV.csv' %(furnace_brass_tag_num)`

---

<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 24, 2021, 2:31pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/6 "2021-06-24T14:31:06Z")

</div>

`'hello {name}'.format(name="bob")` definitely works in jython 2.7

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [June 24, 2021, 2:32pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/7 "2021-06-24T14:32:13Z")

</div>

oh? i thought it was python 3+

edit: seems its 2.6  
and fstring format is 3.6

---

<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 24, 2021, 2:34pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/8 "2021-06-24T14:34:36Z")

</div>

Seems like python 3 is all about f-strings, which are super convenient and would be a great addition to Ignition, but I don’t think jython is going to catch up any time soon.

---

<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 24, 2021, 2:37pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/9 "2021-06-24T14:37:10Z")

</div>

Yes you definitely need `\\` if you are using backslashes. If your directory had a folder starting with a lowercase n then `"C:\new Folder"` I think would be interpreted as `C:` then a newline (because \n denotes new line), then `"ew Folder"`. Does double backslashes solve your problem?

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [June 24, 2021, 2:46pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/10 "2021-06-24T14:46:13Z")

</div>

I did get label to come up with correct syntax by using double \.

Still can’t get the script to work.

I have the following lines of code and I am getting this error:

```auto
	elif state == 10 and command == 'upload_recipe':
		# Look for recipe .csv file, set part/operation, get setpoints from database, and update state
		filepath = 'C:\\Recipe In\\BT{}\\WG10-CSV.csv'.format(furnace_brass_tag_num).value
# logger.info(toString(filepath))
		if system.file.fileExists(filepath):

```

I get the following error on the logger:  
Error running action ‘dom.onKeyUp’ on Templates/Embedded/RecipeView@C$0:1/root/Scanner\_Container/OperationID/Field: Traceback (most recent call last): File “function:runAction”, line 7, in runAction File “module:RecipeControl”, line 59, in update\_recipe\_state\_machine NameError: global name ‘toStr’ is not defined

Line 59 is the one where I am setting filepath

---

<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:** [June 24, 2021, 2:48pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/11 "2021-06-24T14:48:49Z")

</div>

`furnace_brass_tag_num.value` perhaps?

`filepath = 'C:\\Recipe In\\BT{}\\WG10-CSV.csv'.format(furnace_brass_tag_num.value)`

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [June 24, 2021, 2:49pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/12 "2021-06-24T14:49:05Z")

</div>

Correction…this is the error I am getting:

Error running action ‘dom.onKeyUp’ on Templates/Embedded/RecipeView@C$0:1/root/Scanner\_Container/OperationID/Field: Traceback (most recent call last): File “function:runAction”, line 7, in runAction File “module:RecipeControl”, line 59, in update\_recipe\_state\_machine AttributeError: ‘str’ object has no attribute ‘value’

I am assuming this is related to the furnace\_brass\_tag\_num value.

I have this same formatting in other places in the script related to reading and writing to tags so not sure why it isn’t working here

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [June 24, 2021, 2:52pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/13 "2021-06-24T14:52:10Z")

</div>

Tried that change and get this error now:

Error running action ‘dom.onKeyUp’ on Templates/Embedded/RecipeView@C$0:1/root/Scanner\_Container/OperationID/Field: Traceback (most recent call last): File “function:runAction”, line 7, in runAction File “module:RecipeControl”, line 59, in update\_recipe\_state\_machine AttributeError: ‘unicode’ object has no attribute ‘value’

```auto
filepath = 'C:\\Recipe In\\BT{}\\WG10-CSV.csv'.format(furnace_brass_tag_num.value)

```

---

<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:** [June 24, 2021, 2:53pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/14 "2021-06-24T14:53:24Z")

</div>

> [@michael.black](#):
>
> `furnace_brass_tag_num`

Where / How is `furnace_brass_tag_num` being set?

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [June 24, 2021, 2:55pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/15 "2021-06-24T14:55:50Z")

</div>

It is being passed into the script for the overall function:

```auto
def update_recipe_state_machine(furnace_brass_tag_num, command=None):
	"""Process state machine updates and trigger control functions.
	
	Params:
		furnace_brass_tag_num (str): Brass tag number of furnace
		command (str): Command to run against recipe state machine
	"""

```

I am using the same parameter elsewhere. Here is an example.

```auto
running = system.tag.read('[BladesideHT]BS/FurnaceBT{}/Machine Running'.format(furnace_brass_tag_num)).value

```

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [June 24, 2021, 2:56pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/16 "2021-06-24T14:56:35Z")

</div>

> [@michael.black](#):
>
> `furnace_brass_tag_num`

its just furnace\_brass\_tag\_num then  
so

> C:\Recipe In\BT{}\WG10-CSV.csv'.format(furnace\_brass\_tag\_num)

---

<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:** [June 24, 2021, 2:58pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/17 "2021-06-24T14:58:28Z")

</div>

Ok, if it’s already coming in as a value, then you shouldn’t need `.value`

The other example is from a tag read, so you need to get the value from the tag’s QualifiedValue

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [June 24, 2021, 3:00pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/18 "2021-06-24T15:00:44Z")

</div>

Awesome, thanks all! Got it to work by changing code to:

```auto
	elif state == 10 and command == 'upload_recipe':
		# Look for recipe .csv file, set part/operation, get setpoints from database, and update state
		filepath = 'C:\\Recipe In\\BT{}\\WG10-CSV.csv'.format(furnace_brass_tag_num)
# logger.info(toString(filepath))
		if system.file.fileExists(filepath):

```

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [June 24, 2021, 3:02pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/19 "2021-06-24T15:02:15Z")

</div>

nice^^ mark the topic solved 😉

---

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [June 24, 2021, 3:06pm UTC](https://forum.inductiveautomation.com/t/create-filepath-string-with-r/48157/20 "2021-06-24T15:06:36Z")

</div>

Done! Didn’t realize that, I should go back and mark some of my other posts solved too

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