nextcloud/server · error · Error

This file/folder is already in that directory

Error message

This file/folder is already in that directory

What it means

Error "This file/folder is already in that directory" thrown in nextcloud/server.

Source

Thrown at apps/files/src/actions/moveOrCopyAction.ts:109

 *
 * @param nodes The nodes to copy/move
 * @param destination The destination to copy/move the nodes to
 * @param method The method to use for the copy/move
 * @param overwrite Whether to overwrite the destination if it exists
 * @yields {AsyncGenerator<void, void, never>} A promise that resolves when the copy/move is done
 */
export async function* handleCopyMoveNodesTo(nodes: INode[], destination: IFolder, method: MoveCopyAction.COPY | MoveCopyAction.MOVE, overwrite = false): AsyncGenerator<void, void, never> {
	if (!destination) {
		return
	}

	if (destination.type !== FileType.Folder) {
		throw new Error(t('files', 'Destination is not a folder'))
	}

	// Do not allow to MOVE a node to the same folder it is already located
	if (method === MoveCopyAction.MOVE && nodes.some((node) => node.dirname === destination.path)) {
		throw new Error(t('files', 'This file/folder is already in that directory'))
	}

	/**
	 * Example:
	 * - node: /foo/bar/file.txt -> path = /foo/bar/file.txt, destination: /foo
	 *   Allow move of /foo does not start with /foo/bar/file.txt so allow
	 * - node: /foo , destination: /foo/bar
	 *   Do not allow as it would copy foo within itself
	 * - node: /foo/bar.txt, destination: /foo
	 *   Allow copy a file to the same directory
	 * - node: "/foo/bar", destination: "/foo/bar 1"
	 *   Allow to move or copy but we need to check with trailing / otherwise it would report false positive
	 */
	if (nodes.some((node) => `${destination.path}/`.startsWith(`${node.path}/`))) {
		throw new Error(t('files', 'You cannot move a file/folder onto itself or into a subfolder of itself'))
	}

	const nameMapping = new Map<string, string>()

View on GitHub (pinned to ecdeb153ff)

When it happens

Trigger: Thrown at apps/files/src/actions/moveOrCopyAction.ts:109 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of nextcloud/server@ecdeb153ff (2026-08-17). Data as JSON: /api/errors/f6cad914b9c1d04f. Report an issue: GitHub.