Plugins / file / JSFile

Release notes for Servoy betas

Plugins / file / JSFile

Postby Rene » Sat Dec 27, 2003 6:10 pm

Hello everyone,

I`ve got a question.

A main function in my database is to open files and it works great with Servoy thanks to this forum. :lol:

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. :?:

Many thanks in advance, Rene
Rene
 
Posts: 121
Joined: Sat Dec 27, 2003 1:33 pm
Location: Venhorst, The Netherlands

Postby jcompagner » Mon Dec 29, 2003 7:25 pm

i don't see any example script but this those work fine at my place:

var contents = plugins.file.getFolderContents("c:/temp");
for(var p=0;p<contents.length;p++)
{
application.output(contents[p] + " " + contents[p].exists());
}
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby Rene » Mon Dec 29, 2003 10:33 pm

Hello Johan,

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

Code: Select all
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.

With kind regards Rene
Rene
 
Posts: 121
Joined: Sat Dec 27, 2003 1:33 pm
Location: Venhorst, The Netherlands

Postby jcompagner » Wed Dec 31, 2003 8:58 pm

Now i see what you are trying to do..

First of all

"if (plugins.file.jsfile.exists(filepath))"

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..

see my code:

var contents = plugins.file.getFolderContents("c:/temp");
for(var p=0;p<contents.length;p++)
{
application.output(contents[p] + " " + contents[p].exists());
}

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...

so you can do this in the next version of servoy:

"plugins.file.convertStringToJSFile(filepath).exists())"

Then it will work fine.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby Rene » Thu Jan 01, 2004 6:48 pm

:D :lol: :D :lol: :D :shock: :shock: :shock: :shock:G R E A T :shock: :shock: :shock: :shock: :lol: :D :lol: :D :lol: :D
jcompagner wrote: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..

see my code:

var contents = plugins.file.getFolderContents("c:/temp");
for(var p=0;p<contents.length;p++)
{
application.output(contents[p] + " " + contents[p].exists());
}

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
Rene
 
Posts: 121
Joined: Sat Dec 27, 2003 1:33 pm
Location: Venhorst, The Netherlands


Return to Latest Releases

Who is online

Users browsing this forum: No registered users and 2 guests