Skip to content

Ability to increment prefix when duplicating file/folder #47014

Closed

Description

  • 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);
}

Activity

  1. iCyberon commented on Mar 30, 2018

    @iCyberon
    Author

    Testing something like /^(\d+)(.*)(\..*)$/ should be enough to handle the case.

  2. added
    file-explorer
    and removed on Apr 1, 2018
  3. added
    feature-request
    on Apr 1, 2018
  4. isidorn commented on Apr 13, 2018

    @isidorn

    If there is a simple PR to handle this case we would be happy to merge it in

  5. added
    help wanted
    on Apr 13, 2018
  6. iCyberon commented on Apr 13, 2018

    @iCyberon
    Author

    Great, I'll make the changes and create PR

  7. added
    verification-needed
    on May 17, 2018
  8. added
    verified
    on May 30, 2018
  9. roblourens commented on May 30, 2018

    @roblourens
    Member

    This caused #50822 which we should take for May

  10. locked and limited conversation to collaborators on Jul 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-requestfile-explorerhelp wantedverification-neededverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions