{"record":{"id":"f2a757d603510234","repo":"pentaho/pentaho-kettle","slug":"folder","errorCode":null,"errorMessage":"folder [","messagePattern":"folder \\[","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":2001,"sourceCode":"      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n\n  public static void createFolder( Bowl bowl, ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n\n    try {\n      if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {\n        FileObject fileObject = null;\n\n        try {\n          fileObject = KettleVFS.getInstance( bowl ).getFileObject( (String) ArgList[0] );\n          if ( !fileObject.exists() ) {\n            fileObject.createFolder();\n          } else {\n            throw new RuntimeException( \"folder [\" + ArgList[0] + \"] already exist!\" );\n          }\n        } catch ( IOException e ) {\n          throw new RuntimeException( \"The function call createFolder is not valid.\" );\n        } finally {\n          if ( fileObject != null ) {\n            try {\n              fileObject.close();\n            } catch ( Exception e ) {\n              // Ignore errors\n            }\n          }\n        }\n\n      } else {\n        throw new RuntimeException( \"The function call createFolder is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );","sourceCodeStart":1983,"sourceCodeEnd":2019,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1983-L2019","documentation":"The createFolder() script helper throws 'folder [name] already exist!' when KettleVFS reports the target path already exists, so creating the folder again is rejected. Note the message is emitted from the else-branch of the exists() check before any folder creation is attempted.","triggerScenarios":"Calling createFolder('path') where fileObject.exists() is true — the directory (or even a file) at that path already exists from a previous run or step.","commonSituations":"Re-running a transformation that creates working directories without cleanup; two steps in the same transformation creating the same folder; a file (not folder) occupying the intended path; timestamped directory logic that collides within the same day/hour.","solutions":["Check existence first with fileExists() and only call createFolder when it returns false.","Use a unique folder name (timestamp/UUID suffix) for per-run directories.","If reuse is fine, just verify the path exists and is a directory, then skip creation.","Clean up or archive old run directories before re-running the transformation."],"exampleFix":"// before\ncreateFolder('/tmp/work');\n// after\nif (!fileExists('/tmp/work')) { createFolder('/tmp/work'); }","handlingStrategy":"validation","validationCode":"if (!fileExists(path)) { createFolder(path); }","typeGuard":"function isNonEmptyString(s) { return typeof s === 'string' && s.trim().length > 0; }","tryCatchPattern":"try { createFolder(path); } catch (e) { if (String(e).indexOf('already exist') >= 0) { /* tolerate reuse */ } else { throw e; } }","preventionTips":["Guard creation with an existence check","Use unique per-run folder names","Clean stale run directories before re-runs"],"tags":["file-io","folder","already-exists","vfs"],"backgroundTag":"file-already-exists","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}