# Scripting

**URL:** <https://forum.inductiveautomation.com/t/scripting/11807>\
**Category:** Ignition\
**Created:** [June 13, 2016, 7:45pm UTC](https://forum.inductiveautomation.com/t/scripting/11807 "2016-06-13T19:45:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DeraEE](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DeraEE](https://forum.inductiveautomation.com/u/DeraEE)\
**Post date:** [June 13, 2016, 7:45pm UTC](https://forum.inductiveautomation.com/t/scripting/11807/1 "2016-06-13T19:45:15Z")

</div>

Hi,

I’m trying to automatically give file paths names with a date according to a timestamp:

[color=#0000FF]date = timeStampString  
results = event.source.parent.getComponent(‘Table’).data  
spreadsheet = system.dataset.dataSetToExcel(1, [results])  
filePath = “C:\Vat Report\Vat 1\” + date + “.xls”  
system.file.writeFile(filePath, spreadsheet)[/color]

but I get the error

[color=#FF0080]Traceback (innermost last):  
File “event:propertyChange”, line 12, in ?  
IOError: The filename, directory name, or volume label syntax is incorrect  
[/color]  
What’s a better approach? ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")Thanks! ![:prayer:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e5a7e3b63facc151ea73e3b45db7bdb3d4bdc316.gif ":prayer:")

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 13, 2016, 8:23pm UTC](https://forum.inductiveautomation.com/t/scripting/11807/2 "2016-06-13T20:23:18Z")

</div>

The vast majority of programming languages give special meaning to backslashes in strings, as a way to specify various special characters. You’ll need to double up every backslash you need to really be a backslash in the string.  
As a modern convenience, many languages’ file I/O libraries will accept unix-standard forward slashes as folder separators on all platforms, converting internally as needed. This is mostly true for Java.  
So, two choices:`filePath = "C:\\Vat Report\\Vat 1\\" + date + ".xls"`Or:`filePath = "C:/Vat Report/Vat 1/" + date + ".xls"`

---

<div class="post-metadata">

**Author:** ![DeraEE](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DeraEE](https://forum.inductiveautomation.com/u/DeraEE)\
**Post date:** [June 13, 2016, 8:59pm UTC](https://forum.inductiveautomation.com/t/scripting/11807/3 "2016-06-13T20:59:02Z")

</div>

I tried:

[color=#0000FF]filePath = “C:\Vat Report\Vat 1\” + name + “.xls”[/color]

and

[color=#0040FF]filePath = “C:/Vat Report/Vat 1/” + name + “.xls”[/color]

and still get the error.😊

---

<div class="post-metadata">

**Author:** ![the\_msp](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@the\_msp](https://forum.inductiveautomation.com/u/the_msp)\
**Post date:** [June 13, 2016, 10:11pm UTC](https://forum.inductiveautomation.com/t/scripting/11807/4 "2016-06-13T22:11:40Z")

</div>

Just double checking… did you typo (or wordo…?)

you have ‘date’ defined…

in your last post you have ‘name’ not ‘date’…

---

<div class="post-metadata">

**Author:** ![DeraEE](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DeraEE](https://forum.inductiveautomation.com/u/DeraEE)\
**Post date:** [June 13, 2016, 10:36pm UTC](https://forum.inductiveautomation.com/t/scripting/11807/5 "2016-06-13T22:36:16Z")

</div>

Sorry about that. Yes it is defined as date and I copied and pasted the file path from the browser, and added the extra slashes as suggested. Is it because I’m adding a parameter to the file path?

“” + param + “”

date = timeStampString  
results = event.source.parent.getComponent(‘Table’).data  
spreadsheet = system.dataset.dataSetToExcel(1, [results])  
filePath = “C:\Vat Report\Vat 1\” + date + “.xls”  
system.file.writeFile(filePath, spreadsheet)

Thanks

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 14, 2016, 12:36am UTC](https://forum.inductiveautomation.com/t/scripting/11807/6 "2016-06-14T00:36:03Z")

</div>

Put in a “print filepath” just before you use it so you can see what you really have.

---

<div class="post-metadata">

**Author:** ![DeraEE](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@DeraEE](https://forum.inductiveautomation.com/u/DeraEE)\
**Post date:** [June 14, 2016, 6:53pm UTC](https://forum.inductiveautomation.com/t/scripting/11807/7 "2016-06-14T18:53:00Z")

</div>

Thanks that worked. My problem was that I made a mistake on the date format expression. I changed it to the following and it works great. Thanks pturmel

dateFormat(toDate({Root Container.t\_stamp}), “MMM d, yyyy”)

---

<div class="post-metadata">

**Author:** ![pweber](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@pweber](https://forum.inductiveautomation.com/u/pweber)\
**Post date:** [May 14, 2020, 11:31am UTC](https://forum.inductiveautomation.com/t/scripting/11807/8 "2020-05-14T11:31:51Z")

</div>

Should a URL be used instead as well? What machine ‘c:’ reference from the Gateway script vs the downloaded Designer (on a separate machine)?  
Should these Gateway Scripts only be coded from the Gateway Host?
