{"record":{"id":"62d5ecf23f73e020","repo":"pentaho/pentaho-kettle","slug":"file","errorCode":null,"errorMessage":"file [","messagePattern":"file \\[","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":1967,"sourceCode":"\n    try {\n      if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {\n        // Object act = actualObject.get(\"_step_\", actualObject);\n        // ScriptValuesMod act = (ScriptValuesMod)Context.toType(scm_delete, ScriptValuesMod.class);\n\n        FileObject fileObject = null;\n\n        try {\n          fileObject = KettleVFS.getInstance( bowl ).getFileObject( (String) ArgList[0] );\n          if ( fileObject.exists() ) {\n            if ( fileObject.getType() == FileType.FILE ) {\n              if ( !fileObject.delete() ) {\n                throw new RuntimeException( \"We can not delete file [\" + (String) ArgList[0] + \"]!\" );\n              }\n            }\n\n          } else {\n            throw new RuntimeException( \"file [\" + ArgList[0] + \"] can not be found!\" );\n          }\n        } catch ( IOException e ) {\n          throw new RuntimeException( \"The function call deleteFile 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 deleteFile is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );","sourceCodeStart":1949,"sourceCodeEnd":1985,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L1949-L1985","documentation":"The deleteFile() script helper throws 'file [name] can not be found!' when KettleVFS reports that the requested path does not exist. This is an existence check before deletion — the path resolved successfully but no file is present.","triggerScenarios":"Calling deleteFile('somePath') where fileObject.exists() returns false: the path is wrong, the file was already deleted, or relative paths resolve to a different working directory than expected.","commonSituations":"Typos or wrong separators in the path; deleting the same file twice in one script/loop; running the transformation from a different working directory so a relative path no longer points at the file; case-sensitive filesystems (Linux) vs the filename's casing.","solutions":["Check the file exists before calling deleteFile (use fileExists()) and skip deletion gracefully if absent.","Use an absolute path instead of a relative one to remove working-directory dependence.","Fix the filename casing/separators for the target OS filesystem.","Verify an earlier step did not already delete or rename the file."],"exampleFix":"// before\ndeleteFile('data/out.csv'); // may not exist\n// after\nif (fileExists('data/out.csv')) { deleteFile('data/out.csv'); }","handlingStrategy":"validation","validationCode":"if (fileExists(path)) { deleteFile(path); }","typeGuard":"function isNonEmptyString(s) { return typeof s === 'string' && s.trim().length > 0; }","tryCatchPattern":"try { deleteFile(path); } catch (e) { if (String(e).indexOf('can not be found') >= 0) { /* already gone: ignore */ } else { throw e; } }","preventionTips":["Always guard deleteFile with fileExists","Use absolute paths to avoid working-directory drift","Match filename casing to the target filesystem"],"tags":["file-io","delete","file-not-found","vfs"],"backgroundTag":"file-not-found","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"}