var File = java.io.File;
var FileUtils = org.apache.commons.io.FileUtils;
var file = new File("./docs");
print(file.isDirectory());
var success = FileUtils.deleteDirectory(file);
And get the error:
>> FileUtils.deleteDirectory(file);
TypeError: Cannot call property deleteDirectory in object [JavaPackage
org.apache.commons.io.FileUtils]. It is not a function, it is
"object". (<stdin>#65)
at <stdin>:65
What is the problem with this code? I guess I'm missing something.
I'm trying to delete a directory/file using the following code:var File = java.io.File;
var FileUtils = org.apache.commons.io.FileUtils;
var file = new File("./docs");
print(file.isDirectory());
var success = FileUtils.deleteDirectory(file);And get the error:
>> FileUtils.deleteDirectory(file);
TypeError: Cannot call property deleteDirectory in object [JavaPackage
org.apache.commons.io.FileUtils]. It is not a function, it is
"object". (<stdin>#65)
at <stdin>:65
addToClasspath("./lib/commons-io-2.0.1.jar")
solved the problem.
But there's another problem I ran into earlier. I tried to use
File.delete(), but Rhino chokes on that, since delete is keyword in
Rhino and E4X. Is there a default approach to wrap method names for
Java classes when the method name is a JavaScript keyword?
Try this code to see the error message:
>> var File = Packages.java.io.File;
>> var file = new File("someFile.txt");
>> file.delete()
js: "<stdin>", line 9: missing name after . operator
js: file.delete()
js: ...........^
> --
> You received this message because you are subscribed to the Google Groups
> "RingoJS" group.
> To post to this group, send email to rin...@googlegroups.com.
> To unsubscribe from this group, send email to
> ringojs+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/ringojs?hl=en.
>
The following (way of accessing JS object properties) should solve this:
`>> file['delete']()`
HTH.
-- Robi
> On Sun, Feb 20, 2011 at 2:07 PM, Simon Oberhammer <si...@nekapuzer.at> wrote:
>> On Sunday, February 20, 2011 12:27:59 PM UTC+1, Raju Bitter wrote:
>>>
>>> I'm trying to delete a directory/file using the following code:
>>>
>>> var File = java.io.File;
>>> var FileUtils = org.apache.commons.io.FileUtils;
>>> var file = new File("./docs");
>>> print(file.isDirectory());
>>> var success = FileUtils.deleteDirectory(file);
>>>
>>> And get the error:
>>> >> FileUtils.deleteDirectory(file);
>>> TypeError: Cannot call property deleteDirectory in object [JavaPackage
>>> org.apache.commons.io.FileUtils]. It is not a function, it is
>>> "object". (<stdin>#65)
>>> at <stdin>:65
>>
>> try with Packages.org.apache.commons.io.FileUtils
>> `java` is just a shortcut for `Packages.java` and the error message is very
>> misleading, because:
>>>> Packages.foo.bar.doesNoExist()
>> TypeError: Cannot call property doesNoExist in object [JavaPackage foo.bar].
>> It is not a function, it is "object". (<stdin>#24)
>> simon
>>
>>
>
>
- Raju