[quote=“Carl.Gould”]
Sorry, there were too many scripts posted here for me to re-create exactly what script you’re using. Please post the script.[/quote]
Ok, here is the code that works:
#get tag of window
tag = event.source.parent.Tag
#prompt user to select file
path = fpmi.file.openFile()
#if user selects a file, and does not click cancel, do this
if path != None:
import fpmi
ext = path[path.rfind(".")+1:]
name = path[path.rfind("\")+1:len(path)-len(ext)-1]
#read in the file as bytes
bytes = fpmi.file.readFileAsBytes(path)
#write the data to the database, and return the id of the new row
fpmi.db.runPrepStmt("INSERT INTO files (tag,name,ext,data) VALUES (?,?,?,?)", (tag,name,ext,bytes))
#refresh the data in the list, as it is set to polling off
fpmi.db.refresh(event.source.parent.getComponent('List'),"data")
This is the code that doesn’t work:
#get tag of window
tag = event.source.parent.Tag
#prompt user to select file
path = fpmi.file.openFile()
#if user selects a file, and does not click cancel, do this
if path != None:
def insertFile(path = path, tag = tag):
import fpmi
ext = path[path.rfind(".")+1:]
name = path[path.rfind("\")+1:len(path)-len(ext)-1]
#read in the file as bytes
bytes = fpmi.file.readFileAsBytes(path)
#write the data to the database, and return the id of the new row
fpmi.db.runPrepStmt("INSERT INTO Files (tag,name,ext,data) VALUES (?,?,?,?)", (tag,name,ext,bytes))
#refresh the data in the list, as it is set to polling off
fpmi.db.refresh(event.source.parent.getComponent('List'),"data")
fpmi.system.invokeAsynchronous(insertFile)
I haven’t tried the new code that Kyle just posted yet. I just want to understand what is going on with the above code first. I’m not a Python expert (yet).