{"record":{"id":"0e9b5a119d2b5701","repo":"baomidou/mybatis-plus","slug":"file-exists-and-is-not-a-directory-unable-to-c","errorCode":null,"errorMessage":"File {} exists and is not a directory. Unable to create directory.","messagePattern":"File (.+?) exists and is not a directory\\. Unable to create directory\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/util/FileUtils.java","lineNumber":47,"sourceCode":"     * Makes a directory, including any necessary but nonexistent parent\n     * directories. If a file already exists with specified name but it is\n     * not a directory then an IOException is thrown.\n     * If the directory cannot be created (or does not already exist)\n     * then an IOException is thrown.\n     *\n     * @param directory directory to create, must not be {@code null}\n     * @throws NullPointerException if the directory is {@code null}\n     * @throws IOException          if the directory cannot be created or the file already exists but is not a directory\n     */\n    public static void forceMkdir(final File directory) throws IOException {\n        if (directory.exists()) {\n            if (!directory.isDirectory()) {\n                final String message =\n                    \"File \"\n                        + directory\n                        + \" exists and is \"\n                        + \"not a directory. Unable to create directory.\";\n                throw new IOException(message);\n            }\n        } else {\n            if (!directory.mkdirs()) {\n                // Double-check that some other thread or process hasn't made\n                // the directory in the background\n                if (!directory.isDirectory()) {\n                    final String message =\n                        \"Unable to create directory \" + directory;\n                    throw new IOException(message);\n                }\n            }\n        }\n    }\n\n    /**\n     * Makes any necessary but nonexistent parent directories for a given File. If the parent directory cannot be\n     * created then an IOException is thrown.\n     *","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/util/FileUtils.java#L29-L65","documentation":"FileUtils.forceMkdir throws IOException when the target path exists but is a regular file, not a directory. The generator needs a directory at that path to write generated files into, and it will not delete or overwrite an existing file, so it fails with the offending path in the message.","triggerScenarios":"outputDir (or any parent the generator must create, e.g. mapper xml output dir) pointing at an existing file — e.g. outputDir(\"src\") where a file named 'src' exists, or a previous run's artifact was redirected onto the same path.","commonSituations":"Reusing an outputDir that a tool or teammate turned into a file; outputDir pointing to a path where a symlink/file was created by another build step; misconfigured globalConfig.setOutputDir with a filename accidentally appended.","solutions":["Check the path printed in the message: `ls -l <path>` will show a file where a directory is expected.","Delete or rename the conflicting file, or point outputDir at a different path.","Verify no trailing filename fragment (e.g. missing separator before a module name) turned the dir path into a file path."],"exampleFix":"// before\nglobalConfig.setOutputDir(\"/proj/out\"); // '/proj/out' is an existing FILE\n\n// after\n// remove or move the file, or choose a fresh dir\nglobalConfig.setOutputDir(\"/proj/out-gen\");","handlingStrategy":"validation","validationCode":"File dir = new File(outputDir);\nif (dir.exists() && !dir.isDirectory()) {\n    throw new IllegalStateException(\"outputDir exists as a FILE, refusing to continue: \" + dir);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use dedicated, empty-per-run output directories (target/generated-sources) instead of shared paths.","Add a pre-flight check that each configured output path is absent or a directory.","Avoid paths that other build steps also create as files."],"tags":["mybatis-plus","code-generator","filesystem","io"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}