Is there a way to check for existence of a folder in pentaho?

耗尽温柔 提交于 2019-12-11 04:28:26

问题


I know that there is a "Check if a folder is empty", but it does not check for existing of the folder.


回答1:


But to use it in Pentaho is more complicated. When creating a Job rather than a transform, straight Java is not directly available (that I know of). The good news is PDI's JavaScript interpreter is Rhino. That means all Java's objects and classes are available to JavaScript. As such the check is pretty easy.

Add a variable or parameter in your job and call it something like dirpath and give it a path to evaluate. Then add a JavaScript step to the job and add put the following code in it:

dirpath = parent_job.getVariable("dirpath");
fileobj = new java.io.File(dirpath);
fileobj.isDirectory();

Control will flow down the Success or Failure paths from this step based on the truth of the last line.

Pentaho will likely add that capability to their Check if File Exists step soon, but in the mean time, this will work. OTOH, might be another good example of a custom plugin that could be written.




回答2:


The isDirectory() method of the File Object should do, what you need.

The Api writes:

Returns: true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise

--> http://docs.oracle.com/javase/6/docs/api/java/io/File.html#isDirectory%28%29




回答3:


On Job level you can use the step 'Checks if files exist' for checking the existance of files but folders aswell.



来源:https://stackoverflow.com/questions/17490806/is-there-a-way-to-check-for-existence-of-a-folder-in-pentaho

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!