Reputation: 2573
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?
Upvotes: 2
Views: 2494
Reputation: 5070
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);
Upvotes: 2