Trying to delete the edge_historian.idb file using a script and have run into a strange issue. This is for my customer’s post-commissioning phase where they want to clear out all of the irrelevant process data, alarms, etc. that occurred during initial startup at their facility so their customer starts with a “clean slate” when their machine gets on site. Here is my script:
import os
filePath = "C:\Program Files\Inductive Automation\Ignition\data\local\tag-historian\edge_historian.idb"
print filePath
if os.path.exists(filePath):
print "The file exists!"
# os.remove(filePath)
# print "File Removed!"
else:
print "The file does not exist!"
I’ve commented out the “os.remove” part for now because I’ve run into a snag where os.path.exists is returning False even though I have double and triple checked that it IS a valid path.
So I started editing the file path to see where I’m going wrong. I started with C:\, and I got a true. I got everything up to C:\Program Files\Inductive Automation\Ignition. When I added the “data” folder to the path, it started returning False. I also tried the os.path.join() method and I encounter the same limitation. As soon as I try to look into the “data” folder or beyond, it stops “finding” the files. I’m kind of at a loss here. Is this a user authorization issue? I edited the Ignition service in Windows so it would log in as an administrator and then restarted the service, but I’m still having the issue.
\ is the escape character in python, so try this
import os
filePath = "C:\\Program Files\\Inductive Automation\\Ignition\\data\\local\\tag-historian\\edge_historian.idb"
print filePath
if os.path.exists(filePath):
print "The file exists!"
# os.remove(filePath)
# print "File Removed!"
else:
print "The file does not exist!"
Interesting. I’ll give it a shot, but I wonder why it worked up to a point and suddenly didn’t. I also used os.path.join and ran into the same thing.
Tried the double backslash and same deal. Works up until I get to the data folder.
What error are you getting?
I tested the code with the modification and it worked, so it might be a permission issue.
OSError: [Errno 2] No such file or directory: 'C:\Program Files\Inductive Automation\Ignition\data'
FWIW, I’m running the Gateway on Windows 10 IoT Enterprise LTSC
Where are you executing the script? If you are executing on the client/designer, is that running on the same machine as the server?
I’m running it in the script console
On a different machine, actually. It’s running from the script console on the Designer on my laptop and it’s connected remotely to the Edge Device.
The script console executes on the machine you are on, not on the server. You will need to run that script from the gateway to have it affect the content on the server.
2 Likes
That makes sense. I don’t have Ignition installed on my host. I run it solely from containers or connect remotely. Which explains why it’s not finding the data folder. It doesn’t actually exist on my local machine, but I used to have Ignition installed, so the rest of the path is there still. I’ll create the script in the project library and try executing it there!
This was the answer. Executing the script from the project scripts works correctly. I forgot that using the script console looks at your local machine where the designer is, not necessarily the Gateway.
1 Like
As an aside, instead of doubling the backslashes you can also use the r raw string prefix to tell the Python interpreter not to escape backslashes in the string literal:
filePath = r"C:\Program Files\Inductive Automation\Ignition\data\local\tag-historian\edge_historian.idb"
Which is nice so you don't have to adjust the path if you're copying it from Explorer or whatever.
Java/Ignition file APIs will also happily accept forward slashes, which avoids the string escaping problem. I don't know offhand if the Jython stdlib os API does or not (I generally recommend not using Jython stdlib imports).
3 Likes