A main function in my database is to open files and it works great with Servoy thanks to this forum.
But now I want to check if a file exits before copying it (if I just copy it, it will create an empty file suggesting the copy was suceeded on windows)
However there is a function in Plugins / file / JSFile called “exists” but it gives me an error using it.
filepath is the name of a field containing the pathname generated by a vbs script.
If (filepath.exists())
Error message while running method
“Exists is no a function”
I`ve tried numberous different ways including JScript
var fso
fso = new ActiveXObject(“Scripting.FileSystemObject”)
If (fso.FileExits(filepath))
Error message while running
something about ActiveXObject not declares as a variable.
Can anyone help me with the correct syntax in servoy.
Well what I was trying do gain is to add a symple feature to the way files are opened as described in this forum.
If the file has been deleted or moved or the pathitem has been changed Windows doesn`t generate a failure but creates an empty file with the filename as you requested.
So what I was trying to do is before the copyfile action check if the file is valid if not an errormessage appears.
This was my code. filepath is a column in my table containing pathnames
if ( !filepath )
{
plugins.dialogs.showErrorDialog( 'Error', 'No Document attached', 'Continue')
return
}
if ( utils.stringMiddle(application.getOSName(), 1, 7) == "Windows")
{
if (plugins.file.jsfile.exists(filepath))
{
var VI_DocViewId = docviewid
plugins.file.copyFile(filepath, plugins.file.getDesktopFolder()+ '/DocView Saved Files/' + filename)
docviewid_docview.newRecord()
docviewid_docview.userdataid = globals.VI_UserDataId
docviewid_docview.docviewid = VI_DocViewId
}
else
{
plugins.dialogs.showErrorDialog( 'Error', 'The document was not found please check path "' + filepath + '".', 'Continue')
}
}
else
{
plugins.dialogs.showErrorDialog( 'Error', 'There was no association found on your system to open this file ' + utils.stringRight(filename, 3), 'Continue')
}
controller.relookup()
But the code “if (plugins.file.jsfile.exists(filepath))” returns an error “The undefined value has no properties.”
I believe it to be very simple but I don`t SEE it a code example providing the correct syntax will help.
btw I`ve tried to import your code into the solution and calculating the parentfolder but recieved the same error without the check it works just fine.
is not legal code.. you can’t have moved that at onces yes?
the jsfile node.. is a return type node. You can use those methods under jsfile only for things that are returned as a JSFile (or array of JSfiles) by the plugin it self..
the method getFolderContents will return a array of JSFile objects then you can use the methods under the JSFile node in the method editor tree.
This i do with contents[p].exists() (remember i have to do [p] because i didn’t return directly a JSFile but an array of JSFiles…
now what you are trying to do is calling those jsfile functions on nothing or on a string.. With a nothing i mean “plugins.file.jsfile” that plugins.file doesn’t have a jsfile property.. so you can’t say: “plugins.file.jsfile”
But i made a change, because what you want is that you have a String object somewhere and you want to test if that string as a file exisits…
now i made a new method convertStringToJSFile(string filename)
that will return a JSFile representation of the given string…
jcompagner:
the jsfile node.. is a return type node. You can use those methods under jsfile only for things that are returned as a JSFile (or array of JSfiles) by the plugin it self..
the method getFolderContents will return a array of JSFile objects then you can use the methods under the JSFile node in the method editor tree.
This i do with contents[p].exists() (remember i have to do [p] because i didn’t return directly a JSFile but an array of JSFiles…
now what you are trying to do is calling those jsfile functions on nothing or on a string.. With a nothing i mean “plugins.file.jsfile” that plugins.file doesn’t have a jsfile property.. so you can’t say: “plugins.file.jsfile”
Now I understand the code example.
Thank you very much for explaining it to me.
And the function “plugins.file.convertStringToJSFile(filepath).exists())” is going to be very handy for a lot of us I think.
The next release, as I read all about, is going to be an enormous improvement on a great program.
Just can`t wait to get my hands on it ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
Thank you very much. Rene