tags:

views:

22

answers:

1

I am trying to delete a folder using Modified Javascript in Pentaho, however the delete keyword is reserved by the PDI compiler (it is used to delete a variable from memory).

Here's what I do:

var source = new java.io.File("some path");
var files = source.list();
for (var i=0; i<files.length; i++) {
    deleteFile(oldpath + "/" + filename); // empty folder from files, works okey
}
source.delete();

And I get a compilation error from Pentaho.

I tried deleteFile on the folder, but apparently deleteFile can't delete a folder.

Any suggestions how to overcome the use of a reserved word?

+1  A: 

There are 2 solutions for your problem:

1.: The better:

Create a Job, import your current Transformation into the Job. In the transformation set the folder name as a variable, in the job use the variable in the delete folders step.

2.: The easier:

Use reflection in the Modified Java Script Value step (tested in Spoon 4.0.1):

var source = new java.io.File("D:\\testdel");
var fileClass = source.getClass();
var delMethod = fileClass.getMethod("delete", null);
delMethod.invoke(source, null);
Adam
invoke! Thanks! (Last night I figured I should move the folder to an archive, and not delete it, but I still wanted to know how to do this).
OmerGertel