{"record":{"id":"b6b2ce515e42feb5","repo":"pentaho/pentaho-kettle","slug":"the-function-call-movefile-throw-an-error","errorCode":null,"errorMessage":"The function call moveFile throw an error : ","messagePattern":"The function call moveFile throw an error : ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":2591,"sourceCode":"            // Source file exists...\n            if ( fileSource.getType() == FileType.FILE ) {\n              // Great..source is a file ...\n              boolean overwrite = false;\n              if ( !ArgList[1].equals( null ) ) {\n                overwrite = Context.toBoolean( ArgList[2] );\n              }\n              boolean destinationExists = fileDestination.exists();\n              // Let's move the file...\n              if ( ( destinationExists && overwrite ) || !destinationExists ) {\n                fileSource.moveTo( fileDestination );\n              }\n\n            }\n          } else {\n            Context.reportRuntimeError( \"file to move [\" + Context.toString( ArgList[0] ) + \"] can not be found!\" );\n          }\n        } catch ( IOException e ) {\n          throw Context.reportRuntimeError( \"The function call moveFile throw an error : \" + e.toString() );\n        } finally {\n          if ( fileSource != null ) {\n            try {\n              fileSource.close();\n            } catch ( Exception e ) {\n              // Ignore errors\n            }\n          }\n          if ( fileDestination != null ) {\n            try {\n              fileDestination.close();\n            } catch ( Exception e ) {\n              // Ignore errors\n            }\n          }\n        }\n\n      } else {","sourceCodeStart":2573,"sourceCodeEnd":2609,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2573-L2609","documentation":"moveFile(source, target) moves a file on disk. This error wraps any java.io.IOException raised while performing the move, e.g. missing target directory, cross-filesystem move failure, or I/O problems, and appends the exception text. Note a source file that simply does not exists produces a different message ('file to move [...] can not be found!').","triggerScenarios":"moveFile(src, dst) where dst's parent directory does not exist, dst is locked/open by another process, permissions deny the move, or the underlying File.renameTo/copy fails with an IOException.","commonSituations":"Target directory not created before the step runs; file still held open by a previous step on Windows; NFS/Windows cross-drive moves; permission differences between the Kettle user and file owner.","solutions":["Create the target directory first in the script: new java.io.File(dstDir).mkdirs().","Verify permissions on source and target paths for the user running Pentaho.","Close any steps/streams holding the file open before moving (especially on Windows).","Fall back to copy+delete if rename fails across filesystems, or use the File Management/Move Files step instead of JS.","Read the appended e.toString() in the message to identify the exact OS-level cause."],"exampleFix":"// before\nmoveFile('/data/in/file.csv', '/data/out/file.csv'); // /data/out may not exist\n// after\nnew java.io.File('/data/out').mkdirs();\nmoveFile('/data/in/file.csv', '/data/out/file.csv');","handlingStrategy":"try-catch","validationCode":"var srcF = new java.io.File(src), dstF = new java.io.File(dst);\nif (srcF.exists() && dstF.getParentFile() != null) dstF.getParentFile().mkdirs();","typeGuard":"function canMove(s, d) { return typeof s === 'string' && typeof d === 'string' && new java.io.File(s).exists(); }","tryCatchPattern":"try { moveFile(src, dst); } catch (e) { Logger.LogError('moveFile IO error: ' + e.message); /* fallback copy+delete */ }","preventionTips":["Create target directories before moving","Ensure no other step/process holds the file open (esp. Windows)","Check OS permissions for the Pentaho runtime user","Read the appended IOException text for the exact OS cause"],"tags":["file-io","javascript","scripting","filesystem"],"backgroundTag":"file-write-failed","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"}