Access a network drive

Hello all,

I would like to be able to pull out all the file names from a folder on my computer (windows) and then put them into a python list, cannot find a way to do that and would appreciate it if you could help me in this regard. Thank you!

Assuming that the computer where your files exist is the same machine that your Ignition gateway is located on, you could do this with the python os library:

import os
folder = 'C:/Path/To/Folder'
fileList = os.listdir(folder)
2 Likes

Thank you very much @swolnisty. Appreciate your help! This works when I have a local drive folder but not for the network drive.

What if the folder is sitting inside the network? This script does not work for that.

image

Does Ignition have read rights to that folder?

https://docs.inductiveautomation.com/display/DOC81/Mapping+a+Network+Drive

2 Likes

You will have to create a mapping of it. So that it appears under your devices/drives instead of under network.


And seems you need to put in some configs too as @Matrix_Engineering linked

1 Like

Look closer at Parya's screenshot for the "F:". The Ignition gateway runs as a service and has no access to any desktop user's mappings. Mappings must be established in the service.

3 Likes

I’m not super familiar with windows, how do you see that ?

1 Like

To whom are you replying to sorry?

The Ignition service can have a map linked as per the documentation link I posted (edit the ignition.conf file).

We can see that Parya’s link is a network location as per their screenshot with the red circled item.

2 Likes

I have done this as well, though I have accomplished this in kind of a strange way. See my reply to the thread below:

In this case, rather than accessing the files from the webserver/webapps/main directory, you would just be checking the contents with the os.listdir() function I mentioned in my previous post.

Edit: I guess there's no real reason why you'd need to create a symbolic link within the Ignition install directory, you could create it anywhere on the gateway machine.

1 Like

deleted

I changed the config file but I get an error.

org.python.core.PyException
java.lang.IllegalArgumentException: Cannot create PyString with non-byte value
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot create PyString with non-byte value
caused by IllegalArgumentException: Cannot create PyString with non-byte value

Here is what I did:
In the config file, I added:

wrapper.share.1.location="\\fileserver\Automation\..."
wrapper.share.1.target=D:
wrapper.share.1.type=DISK


wrapper.ntservice.account=username
wrapper.ntservice.password=pass
wrapper.share.1.account=domain\username
wrapper.share.1.password=pass

Then stop/start the gateway and I used the script below for my button:

	import os
	folder = "\\fileserver\Automation\..."
	fileList = os.listdir(folder)
	self.getSibling("TextArea").props.text=fileList

You don't put quotes into the conf for a file path, and also no 3 dots, for the full folder it is:

wrapper.share.1.location=\\fileserver\Automation\

I just did that for the demonstration only. I put the actual full path there, also since the location path has spaces, I need to wrap the value in double quotes

Try:

        import os
	folder = "D:\"
	fileList = os.listdir(folder)
	self.getSibling("TextArea").props.text=fileList
1 Like

When I write the script below in the config file:

wrapper.share.1.location="\\fileserver\Automation\..."
wrapper.share.1.target=D:
wrapper.share.1.type=DISK

It means that I should be able to see that folder in my D drive, correct? If this is the case, I do not see any new folder that has been added to my D drive.

No, you are telling Ignition service that if a script looks for contents of D:\ then is it as \fileserver\Automation\

It does not create a windows mapped drive

1 Like

Just for clarity, the share location should be an already existing folder and the target is the alias by which Ignition accesses that folder.

1 Like

So as an example:

If I have a folder in my network drive with some images in it like:

\\fileserver\Automation\MES Ignition for program\sample Image

When I write this:

wrapper.share.1.location="\\fileserver\Automation\..."
wrapper.share.1.target=D:
wrapper.share.1.type=DISK

I need to have a folder set up with the same images and folder path in my D drive too? It is a bit confusing what needs to be done. Let’s say now I have a new folder in my D drive, then do I need to change the script below?

wrapper.share.1.location="\\fileserver\Automation\..."
wrapper.share.1.target=D:
wrapper.share.1.type=DISK

This does nothing.

wrapper.share.1.location="\\fileserver\Automation\"

will grant access to:

\\fileserver\Automation\MES Ignition for program\sample Image.jpg

If you already have a mapped drive called D on your server, is it the one that has the Automation folder that you want Ignition access to?

1 Like