octobercms/october · warning · ApplicationException

editor::lang.filesystem.already_exists

Error message

editor::lang.filesystem.already_exists

What it means

editorCreateDirectory assembles the target as basePath/parent/newName and checks file_exists() plus is_dir() before creating anything. If a directory already exists at that exact location it throws editor::lang.filesystem.already_exists, preventing accidental overwrite of theme directories.

Source

Thrown at modules/editor/traits/FileSystemFunctions.php:44

        if (!strlen($newName)) {
            throw new ApplicationException(Lang::get('editor::lang.filesystem.directory_name_cant_be_empty'));
        }

        if (!$this->validateFileSystemPath($newName)) {
            throw new ApplicationException(Lang::get('editor::lang.filesystem.invalid_path'));
        }

        if (strlen($parent) && !$this->validateFileSystemPath($parent)) {
            throw new ApplicationException(Lang::get('editor::lang.filesystem.invalid_path'));
        }

        if (!$this->validateFileSystemName($newName)) {
            throw new ApplicationException(Lang::get('editor::lang.filesystem.invalid_name'));
        }

        $newFullPath = $basePath.'/'.$parent.'/'.$newName;
        if (file_exists($newFullPath) && is_dir($newFullPath)) {
            throw new ApplicationException(Lang::get('editor::lang.filesystem.already_exists'));
        }

        if (!File::makeDirectory($newFullPath, 0755, true, true)) {
            throw new ApplicationException(Lang::get(
                'editor::lang.filesystem.error_creating_directory',
                ['name' => $newName]
            ));
        }
    }

    /**
     * editorRenameFileOrDirectory
     */
    protected function editorRenameFileOrDirectory($basePath, $name, $originalPath, $allowedFileExtensions)
    {
        $newName = trim($name);
        if (!strlen($newName)) {
            throw new ApplicationException(Lang::get('editor::lang.filesystem.name_cant_be_empty'));

View on GitHub (pinned to b608633a7e)

Solutions

  1. Refresh the file tree and pick a different, unused name.
  2. Guard against double submission (disable the create button until the request finishes).
  3. On case-insensitive filesystems, choose a name differing by more than letter case.
  4. If the directory is intended, reuse it instead of creating a duplicate.

Example fix

// before
$name = 'partials'; // already exists
$this->editorCreateDirectory($basePath, $name, $parent);

// after
if (is_dir($basePath.'/'.$parent.'/'.$name)) {
    // reuse the existing directory
} else {
    $this->editorCreateDirectory($basePath, $name, $parent);
}
Defensive patterns

Strategy: validation

Validate before calling

$target = $basePath.'/'.$parent.'/'.$newName;
if (is_dir($target)) {
    throw new \ValidationException(['name' => "A directory named '{$newName}' already exists"]);
}

Prevention

When it happens

Trigger: Creating a directory that already exists (e.g. 'assets' under a theme root); duplicate submissions when the user double-clicks 'create'; a case-insensitive filesystem where 'Partials' collides with 'partials'; stale UI state listing an outdated tree.

Common situations: Editor tree not refreshed after a previous create; race between two browser tabs both creating the same folder; deploying to macOS/Windows where case-insensitivity turns distinct names into collisions.

Related errors


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/13a0461c69f07d5a. Report an issue: GitHub.