Deleting Files

I have a file importing into my DB after I open a window.I want to delete this file after the import. What scripting would I use for this.

I’m sorry, could you explain a bit more what you mean? You’re importing a file into your DB? As a BLOB row in a table? You’d just issue a SQL “DELETE” statement to delete that row. I must be missing something…

I am importing a text file. After the import I want to delete this file.

Ah, sorry, that makes sense now. I shouldn’t answer posts before I have my coffee!

Here is an example script for deleting a file:

[code]filePath = “C:\MyFile.txt”

Do import routine here…

This is the delete

from java.util import File
f = File(filePath)
if f.exists() and f.isFile():
f.delete()
else:
print "File “, filePath, " doesn’t exist”[/code]

Hope this helps,

EDIT: the line “from java.util import File” above should be “from java.io import File”

Should I just replace the file path with mine and it will work? This file is on another computer.

Yes, it should work with network paths too.

I have added this script to a push button to try to get it to work. It keeps throwing up an error. I copied it below. I have moced this file to my c drive also. Here is the script I am using. I am only trying to delete the file now.

filePath = “\c:\extdat.lis”
from java.util import File
f = File(filePath)
if f.exists() and f.isFile():
f.delete()
else:
print "File “, filePath, " doesn’t exist”

Here is the error.

Traceback (innermost last):
File “”, line 2, in ?
ImportError: cannot import name File

at org.python.core.Py.ImportError(Py.java)
at org.python.core.imp.importFromAs(imp.java)
at org.python.core.imp.importFrom(imp.java)
at org.python.pycode._pyx48.f$0(<event>:2)
at org.python.pycode._pyx48.call_function(<event>)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at com.calmetrics.factoryhmi.application.script.ScriptManager.runCode(ScriptManager.java:228)
at com.calmetrics.factoryhmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:144)
at com.calmetrics.factoryhmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:285)
at com.calmetrics.factoryhmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:54)
at $Proxy0.actionPerformed(Unknown Source)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Sorry, my mistake. It should be:

from java.io import File