pentaho/pentaho-kettle · error · RuntimeException

We can not delete file [

Error message

We can not delete file [

What it means

The deleteFile() script helper resolves the file via KettleVFS, checks it exists and is a regular file, then calls fileObject.delete(). If the VFS layer reports the delete() call as unsuccessful (returned false), the helper throws 'We can not delete file [name]!'.

Solutions

  1. Ensure no other step/process holds the file open; close streams or re-order steps so the file is finished being read/written before deletion.
  2. Verify the process user has write permission on the file's parent directory (delete requires directory write access).
  3. Check the file is not read-only and remove the read-only flag if needed.
  4. Wrap deletion with retry logic or check existence again after failure; if it must succeed, delete manually and treat the script call as best-effort.
  5. Consider using a dedicated 'Delete files' transformation step which reports errors through Kettle's normal error handling.

Example fix

// before
deleteFile('/tmp/lock.txt'); // file still open by earlier step
// after
// ensure previous step finished and stream is closed, then:
var f = new java.io.File('/tmp/lock.txt');
if (f.exists()) { java.nio.file.Files.delete(java.nio.file.Paths.get('/tmp/lock.txt')); }
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure the target is a deletable file first
if (!fileExists(path)) { /* skip */ }

Type guard

function isDeletableStringPath(p) { return typeof p === 'string' && p.length > 0; }

Try / catch

try { deleteFile(path); } catch (e) { // retry after delay or log and continue
}

Prevention

When it happens

Trigger: Calling deleteFile('path') where the target exists as a FILE but fileObject.delete() returns false — typically because the OS refuses the delete (open handles, read-only attribute, or lack of write permission on the parent directory).

Common situations: Deleting a file that another process (or an earlier step in the same transformation) still holds open; deleting files on read-only mounts or without permissions; Windows file locking; deleting files currently being written by a previous transform step.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/733ce742fe544344. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:1962

    }
  }

  public static void deleteFile( Bowl bowl, ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {

    try {
      if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {
        // Object act = actualObject.get("_step_", actualObject);
        // ScriptValuesMod act = (ScriptValuesMod)Context.toType(scm_delete, ScriptValuesMod.class);

        FileObject fileObject = null;

        try {
          fileObject = KettleVFS.getInstance( bowl ).getFileObject( (String) ArgList[0] );
          if ( fileObject.exists() ) {
            if ( fileObject.getType() == FileType.FILE ) {
              if ( !fileObject.delete() ) {
                throw new RuntimeException( "We can not delete file [" + (String) ArgList[0] + "]!" );
              }
            }

          } else {
            throw new RuntimeException( "file [" + ArgList[0] + "] can not be found!" );
          }
        } catch ( IOException e ) {
          throw new RuntimeException( "The function call deleteFile is not valid." );
        } finally {
          if ( fileObject != null ) {
            try {
              fileObject.close();
            } catch ( Exception e ) {
              // Ignore errors
            }
          }
        }

View on GitHub (pinned to f3058517a1)