System.file.writeFile issue creating new file

I am currently using Ignition 8.1.14 and windows server 2019.
I have created button function which create XML File and update it if it is same file.
Is there different function to create a new file in same folder.

When i try to create a new file using System. File. Write File function i am getting error as specified below.

IOError: [Errno 2] File not found - D:\MGILL\WM_25-Feb-2022 11:46:11.xml (The filename, directory name, or volume label syntax is incorrect)

Copy of sample code which is as follow:

Write the xml to a file.

fileName = (‘D:/MGILL/WM_’+ DateTime + ‘.xml’)
if system.file.fileExists(fileName):
system.file.writeFile(fileName, xmlOut)
system.gui.messageBox(“No, it doesn’t exist”)
file = (‘D:/MGILL/WM_’+ DateTime + ‘.xml’ )
if file:
system.file.writeFile(file, xmlOut)

Any suggestions?

Is there a colon in your datetime string? Those aren’t legal in Windows filenames.

As @pturmel said


That is the problem :

Thank Pturmel and Jespinmartin1. Yes it was " :" in the date and time format. once i corrected it. It is working fine now.
Thanks Guys you are Dam good…

Tip: use the </> code formatting button to preserve indents and apply syntax highlighting. Can you fix your original post using the edit button (pencil icon)? Thanks.