# Combine a "String" and a Tag Value in a file name

**URL:** <https://forum.inductiveautomation.com/t/combine-a-string-and-a-tag-value-in-a-file-name/17653>\
**Category:** General Discussion\
**Created:** [April 10, 2018, 2:23am UTC](https://forum.inductiveautomation.com/t/combine-a-string-and-a-tag-value-in-a-file-name/17653 "2018-04-10T02:23:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwoolnough](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@rwoolnough](https://forum.inductiveautomation.com/u/rwoolnough)\
**Post date:** [April 10, 2018, 2:23am UTC](https://forum.inductiveautomation.com/t/combine-a-string-and-a-tag-value-in-a-file-name/17653/1 "2018-04-10T02:23:24Z")

</div>

Hi All,  
I have another “Newbie” question. I have searched previous topics with no success and I’m not even sure if what I’m trying to achieve is possible.  
I am trying to combine a “string” with a tag value to create a file name when using ‘ExportCSV’.

I have created a tag called 'FileDate" = The current date in the format “yyyyMMdd”. I am trying to combine this tag with a string to create a new file name as the name of the saved file prompt when exporting to a csv.  
In the script below, I would like the ‘FileName’ = Products\_20180410  
I appears that the “ExportCSV” requires a literal string as a file name. Is it possible to substitute a tag for the file name?

FileDate = system.date.now()  
system.date.format(FileDate, “yyyyMMdd”)

table = event.source.parent.getComponent(“Table”)  
filePath = system.dataset.exportCSV(‘C:\SiteOverview\FileName’, 1, table.data)  
if filePath != None:  
system.net.openURL(“file:///”+filePath.replace(’\’,’/’))

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [April 10, 2018, 9:36am UTC](https://forum.inductiveautomation.com/t/combine-a-string-and-a-tag-value-in-a-file-name/17653/2 "2018-04-10T09:36:43Z")

</div>

So you’re just trying to concatenate strings? In python you can use the `+` operator like this:

```auto
filePath = 'C:/My/Directory/' + system.tag.read('myTagPath').value

```

But I guess you don’t completely understand what your code is doing, so perhaps I should add some comments to your code.

```auto
FileDate = system.date.now() # This saves the current time under the FileDate variable, as a Java date
system.date.format(FileDate, "yyyyMMdd") # This line doesn't do anything. The format function doesn't alter the arguments, but returns a string. So you need to assign the result to something

table = event.source.parent.getComponent("Table")
filePath = system.dataset.exportCSV('C:\SiteOverview\FileName', 1, table.data)
# The line above asks the user to save the data of the table under a fixed path.
# Note that Python uses the \ as a special character,
# so you either need to use double \\, like "C:\\My\\Directory"
# or you can use a forward / (which also works on Windows), like "C:/My/Directory"
# or you can use raw strings like r"C:\My\Directory"

if filePath != None:
    system.net.openURL("file:///"+filePath.replace('\','/')) # this line again won't work due to the '\' string which even messes up the syntax highlighting at this point

```

---

<div class="post-metadata">

**Author:** ![rwoolnough](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@rwoolnough](https://forum.inductiveautomation.com/u/rwoolnough)\
**Post date:** [April 10, 2018, 9:56am UTC](https://forum.inductiveautomation.com/t/combine-a-string-and-a-tag-value-in-a-file-name/17653/3 "2018-04-10T09:56:55Z")

</div>

Thanks for the reply and the explanation. My aim is to concentrate the 2 strings to prompt the operator of the appropriate file name to save the “.csv” file under  
The 1st string is a “constant or fixed string” = product and the 2nd string is the tag “filedate” which will change with a change of date. i.e. Today the file name will be product\_20180410.csv and tomorrow it will be product\_20180411.csv  
Am I correct in thinking that using the “system.dataset.exportCSV()” instruction that I can only use a “fixed” string, not a string derived from a tag?  
I will review my code and have another attempt at a later stage as I am out on site and not in a position to make attempts now.  
Again thanks for the explanation.  
Woolie

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [April 10, 2018, 10:25am UTC](https://forum.inductiveautomation.com/t/combine-a-string-and-a-tag-value-in-a-file-name/17653/4 "2018-04-10T10:25:03Z")

</div>

> [@rwoolnough](#):
>
> Am I correct in thinking that using the "system.dataset.exportCSV()" instruction that I can only use a "fixed" string, not a string derived from a tag?

No, strings you get from a tag value (given the tag is a string), is just the same as a hard-coded string. Once you have the string assigned to a variable, there's no difference for the exportCSV function.

---

<div class="post-metadata">

**Author:** ![rwoolnough](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@rwoolnough](https://forum.inductiveautomation.com/u/rwoolnough)\
**Post date:** [April 10, 2018, 10:56am UTC](https://forum.inductiveautomation.com/t/combine-a-string-and-a-tag-value-in-a-file-name/17653/5 "2018-04-10T10:56:35Z")

</div>

Great! Again thanks for the help. Hopefully I can get things working as I require.  
Woolie

---

<div class="post-metadata">

**Author:** ![rwoolnough](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@rwoolnough](https://forum.inductiveautomation.com/u/rwoolnough)\
**Post date:** [April 13, 2018, 1:51am UTC](https://forum.inductiveautomation.com/t/combine-a-string-and-a-tag-value-in-a-file-name/17653/6 "2018-04-13T01:51:29Z")

</div>

I’m not sure if anybody will read this topic as it has been quite for a couple of days, but I have finally got back onto my Ignition project.  
I have modified my initial code (as above) and things seem to work better but not completely  
I have used “system.tag.write” function to write the formatted date value into "mydate’ .  
I have saved the formatted date to a tag (mydate created as a memory tag sting) but when I try to combine strings it returns a error that it cannot concentrate a string and an ‘int’  
filePath = ‘C:/My/Directory/’ + system.tag.read(‘mydate’).value  
I have also tried using the “str” function to convert ‘mydate’ to a string.  
Can someone explain how I convert ‘mydate’ which comes from formatting a date to a string.  
Thank you  
Woolie

---

<div class="post-metadata">

**Author:** ![accyroy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/accyroy/32/3386_2.png) [@accyroy](https://forum.inductiveautomation.com/u/accyroy)\
**Post date:** [April 13, 2018, 2:09am UTC](https://forum.inductiveautomation.com/t/combine-a-string-and-a-tag-value-in-a-file-name/17653/7 "2018-04-13T02:09:48Z")

</div>

I’d use string formatting for this:

```auto
filePath = 'C:/My/Directory/%d' % system.tag.read('mydate').value

```

%d is a placeholder for numbers, if you wanted to put in a string value you’d use %s.

---

<div class="post-metadata">

**Author:** ![rwoolnough](https://avatars.discourse-cdn.com/v4/letter/r/3e96dc/32.png) [@rwoolnough](https://forum.inductiveautomation.com/u/rwoolnough)\
**Post date:** [April 13, 2018, 3:33am UTC](https://forum.inductiveautomation.com/t/combine-a-string-and-a-tag-value-in-a-file-name/17653/8 "2018-04-13T03:33:25Z")

</div>

Thank you for the prompt explanation  
Things are looking good again  
Woolie.
