File path exist, but getting error "The system cannot find the path specified"

Hi all, i have a scheduled Gateway Event Script as below:
image

def dataExport():
	#query data
	data = system.db.runNamedQuery(something)
	
	#export to csv
	csvData = system.dataset.toCSV(data)
	
	#check if folder exist
	folderPath = "C:\\test"
	if system.file.fileExists(folderPath):
		#export file
		filePath = folderPath + "\\some_exported_file.csv"
		system.file.writeFile(filePath, csvData)		
	else:
		dummy = 1

Now, the file is able to export, but at the same time i am getting error:

java.io.FileNotFoundException: C:\Windows\Temp\jetty-0_0_0_0-8088-main-_-any-9867179302079148073\WicketFilter-filestore\1197\5854\node0sbs7tgpi2g3xshtcucvixzjr0\data (The system cannot find the path specified)

at java.base/java.io.RandomAccessFile.open0(Native Method)

at java.base/java.io.RandomAccessFile.open(Unknown Source)

at java.base/java.io.RandomAccessFile.(Unknown Source)

at java.base/java.io.RandomAccessFile.(Unknown Source)

at org.apache.wicket.pageStore.DiskDataStore$SessionEntry.getFileChannel(DiskDataStore.java:432)

at org.apache.wicket.pageStore.DiskDataStore$SessionEntry.savePage(DiskDataStore.java:350)

at org.apache.wicket.pageStore.DiskDataStore.storeData(DiskDataStore.java:188)

at org.apache.wicket.pageStore.AsynchronousDataStore$PageSavingRunnable.run(AsynchronousDataStore.java:355)

at java.base/java.lang.Thread.run(Unknown Source)

Am i missing a step somewhere?
Many thanks in advance!

I presume you're looking for this folder on your gateway and not locally?

Yes.
The files managed to saved in the mentioned folder as well.

@nminchin How can you open a file on the server where the gateway is installed?

From where? Perspective? Vision? Gateway script?

Perspective and gateway/tag script are all run in the gateway scope, so you can just use the normal python methods with the os library

for (dirPath, dirs, files) in os.walk(filePath):
   print files
   break

from memory will walk recursively through a folder. Break it after the first run to make it not recursive

Or just don't put it in a loop.

root, dirs, files = next(os.walk('path'))

alternatively, you could use os.listdir, which returns everything that's at the specified path.
You can filter for files only with isfile(), which you can import from os.path

from os import listdir
from os.path import isfile, join

files = [f for f in os.listdir(path) if isfile(join(path, f))]

from vision, using the pdf reader

From Vision it's trickier. However the easiest method is to create a fileshare and access the files using the UNC path to it

You can use system.util.sendRequest() to message a handler in the gateway. Such a handler can open a file for you and return the bytes. Then assign those bytes to the PDF Viewer.