Skip to content

Ability to increment prefix when duplicating file/folder #47014

@iCyberon

Description

@iCyberon
  • VSCode Version: 1.22.0-insider
  • OS Version: macOS 10.13.3

Currently VSCode increments suffix when copying a file. Copying file.1.ext makes file.2.ext. But there are cases when the version is specified in prefix not suffix, for instance when dealing with migrations we have files like 001-name.ext, copying this results in creating a file named 001-name.1.ext which is not the desired result.

It would be great if VSCode could detect and increment the prefix if needed. It also requires minimal changes to incrementFileName method to add the functionality.

function incrementFileName(name: string, isFolder: boolean): string {

	// file.1.txt=>file.2.txt
	if (!isFolder && name.match(/(.*\.)(\d+)(\..*)$/)) {
		return name.replace(/(.*\.)(\d+)(\..*)$/, (match, g1?, g2?, g3?) => { return g1 + (parseInt(g2) + 1) + g3; });
	}

	// file.txt=>file.1.txt
	const lastIndexOfDot = name.lastIndexOf('.');
	if (!isFolder && lastIndexOfDot >= 0) {
		return strings.format('{0}.1{1}', name.substr(0, lastIndexOfDot), name.substr(lastIndexOfDot));
	}

	// folder.1=>folder.2
	if (isFolder && name.match(/(\d+)$/)) {
		return name.replace(/(\d+)$/, (match: string, ...groups: any[]) => { return String(parseInt(groups[0]) + 1); });
	}

	// file/folder=>file.1/folder.1
	return strings.format('{0}.1', name);
}

Metadata

Metadata

Assignees

Labels

feature-requestRequest for new features or functionalityfile-explorerExplorer widget issueshelp wantedIssues identified as good community contribution opportunitiesverification-neededVerification of issue is requestedverifiedVerification succeeded

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions