File path to include computer name

I currently have a file path in a script just accessing a file path on the local C drive.

Now I want to actually look for another computer on the network that Ignition can access

The code I have right now is:

filepath = ‘C:\Recipe\BT\*.csv’

How would I change this line of code include the computer name? The computer name is AI964056

You should just be able to set the filepath to \\AI964056\Recipe\BT\*.csv and it would work, assuming you have a file share established with that path. Permissions could be an issue in this case, but can be overcome based on the permissions granted when creating the file share.

The other option is to map a network drive in Windows to the computer, and this would create a Network Drive that you could reference. When you do this, it would be whatever you selected as the network drive letter (i.e. X:\). This allows you to define and save the credentials and not worry about it with the other option.

1 Like

hmmm. tried this and no luck

filepath = ‘\AI964056\C:\Recipe\BT*.csv’

now its one the D drive also so how would I include the D drive in the string?

You cannot automatically access remote drives, unless an administrator of the target computer. In which case the share would be \\\\AI964056\\C$\..... Otherwise the target computer must have share names established deliberately.

1 Like

For file paths in script, I would recommend either using the raw string flag
r'\\AI964056\shared folder'
Or change all of your back slashes to forward slashes
'//AI964056/shared folder'

Backslashes are a special character in python and are used to escape certain other characters

1 Like

And if you are using backslashes I believe you then need a quadruple, similar to how you’d need a double to browse a remote PC in windows explorer - double a single, and double the double for remote path

1 Like

Only need double if not using raw and that’s so that you escape the escape character function

1 Like

I have two VM’s. I put the file on the second VM. The computer name is:


The file is located on this second computer in the folder:

Test button along with custom property to see if file is found:
image
Script on button:

I also tried this:

Still no luck.

Is the share set up on the second PC?
Can you access the share through the file explorer of the first PC?

I didn’t initially. I just set up the following on the second computer which has the file I want to access from the first computer.


When I left click here is the link I can copy:
Recipe In (file://AI546945/Recipe%20In)
I dont have to do anything on the first computer correct?
Also do I have to change the script based on the shared link?
Thanks.

Only to verfy you can get to the share:

If you can, then it looks like your path would be //AI546945/Recipe In/123_234.csv

1 Like

Here is what I see on first computer:


This confirms I can see the folder from the second computer on the first computer.
I have the csv file as 123_234.csv and also added a blank test.txt file.
I created a new view with just this button and have a custom property on the page as CSVFILE.
Here is the view:
image
Here is the event script:

Here is what I still get:
image
File is still not found.
Any other thoughts?

When running in Perspective’s context, the script is actually executing on the gateway. By default, the gateway runs under the LOCAL_SYSTEM account, which does not have access to any network resources. Have you changed the user the Ignition gateway runs as?

1 Like

Hmm, could you explain more? This is probably it though. I am pretty sure I have everything else setup correctly

Go to windows services, find the one that Ignition runs under, right click and properties and there you can change the account it runs under

1 Like

Awesome! I figured out how to change it and it worked. If My next question is if I change it does it affect anything else related to Ignition if it isn’t using the LOCAL_SYSTEM anymore?

Does the user have to login as this user in order for ignition to operate correctly?

Nope, this is (mostly) irrelevant to Ignition; it’s just up to Windows and its permissions. Basically, to run any ‘persistent’ application (Windows calls them services) you have to choose some set of permissions to run under, and Windows defaults to this fairly restrictive one for safety and security reasons.

Ignition itself doesn’t directly care about this; all of our authentication and authorization is happening in a different layer. The only things it really affects are filesystem or network permissions on the gateway machine itself.

2 Likes