Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incrementFileName incrementing incorrect section of file name #54728

Closed
xelvis42 opened this issue Jul 20, 2018 · 7 comments · Fixed by #55961
Closed

incrementFileName incrementing incorrect section of file name #54728

xelvis42 opened this issue Jul 20, 2018 · 7 comments · Fixed by #55961
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug file-explorer Explorer widget issues help wanted Issues identified as good community contribution opportunities *out-of-scope Posted issue is not in scope of VS Code
Milestone

Comments

@xelvis42
Copy link

xelvis42 commented Jul 20, 2018

Issue Type: Bug

I have a file named F1000-v117.au3. When copying/pasting the file, it creates a file named F1001-v117.au3. This is not the expected result. F1000 is the name of the file and not a version number that should be incremented.

Changing the regex within the incrementFileName function fixes the issue. Basically, make sure the first section of the file name is numeric only.

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

	[other code...]

// 1.file.txt=>2.file.txt
    let prefixFileRegex = RegExp('(\\d+)(' + separators + '.*)(\\..*)$');
    if (!isFolder && name.match(prefixFileRegex)) {
      return name.replace(prefixFileRegex, (match, g1?, g2?, g3?) => {
        let number = parseInt(g1);
        return number < maxNumber
          ? this.pad(number + 1, g1.length) + g2 + g3
          : this.format('{0}{1}.1{2}', g1, g2, g3);
      });
    }
        [other code...]
}

to

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

	[other code...]

// 1.file.txt=>2.file.txt
    let prefixFileRegex = RegExp('(\\d$)(' + separators + '.*)(\\..*)$');
    if (!isFolder && name.match(prefixFileRegex)) {
      return name.replace(prefixFileRegex, (match, g1?, g2?, g3?) => {
        let number = parseInt(g1);
        return number < maxNumber
          ? this.pad(number + 1, g1.length) + g2 + g3
          : this.format('{0}{1}.1{2}', g1, g2, g3);
      });
    }
        [other code...]
}

VS Code version: Code 1.25.1 (1dfc5e5, 2018-07-11T15:43:11.471Z)
OS version: Windows_NT ia32 6.1.7601

System Info
Item Value
CPUs Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz (8 x 2693)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: disabled_software
video_decode: enabled
video_encode: enabled
vpx_decode: unavailable_software
webgl: enabled
webgl2: enabled
Memory (System) 2.92GB (0.12GB free)
Process Argv C:\Program Files\Microsoft VS Code\Code.exe
Screen Reader yes
VM 0%
@isidorn
Copy link
Contributor

isidorn commented Jul 23, 2018

@isidorn isidorn added bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities file-explorer Explorer widget issues labels Jul 23, 2018
@isidorn isidorn added this to the Backlog milestone Jul 23, 2018
@Krzysztof-Cieslak
Copy link
Contributor

I'll take a look tomorrow.

@roblourens
Copy link
Member

F1000-v117.1.au3 is the expected result right?

@roblourens roblourens added the verified Verification succeeded label Aug 29, 2018
@roblourens
Copy link
Member

Actually it seems like other cases are broken now.

  • Have a file test1.txt, copy and paste it
  • The new file is test1.1.txt, in 1.26 it was test2.txt

@roblourens roblourens reopened this Aug 29, 2018
@bpasero bpasero added the candidate Issue identified as probable candidate for fixing in the next release label Aug 30, 2018
@isidorn
Copy link
Contributor

isidorn commented Aug 30, 2018

Thanks for finding that @roblourens
Due to that I had to revert the original fix. So now copying test1.txt gives test2.txt
However this issue is now not fixed, but it was like that in previous stable so nothing urgent -> removing mielstone
@Krzysztof-Cieslak let me know if you want to fix your fix and provide a working PR. Thanks

@isidorn isidorn removed candidate Issue identified as probable candidate for fixing in the next release verified Verification succeeded labels Aug 30, 2018
@isidorn isidorn modified the milestones: August 2018, On Deck Aug 30, 2018
@helsont
Copy link

helsont commented Sep 14, 2018

Hey guys, I took a crack at fixing this regex have some questions on how the naming / number schema works and I want to make sure I have an understanding of the naming schema.

We have our cases here:

suffix:

file.1.txt=>file.2.txt

prefix:

1.file.txt=>2.file.txt

single number:

1.txt=>2.txt

no number:

file.txt=>file.1.txt

ends with number:

folder.1=>folder.2

mixed (new case / why the above PR broke):

name1.txt=>name1.1.txt
name1.test.txt=>name1.test.1.txt (???)

prefixed with number:

1.folder=>2.folder

The issue is that mixing letters and numbers triggers the prefix regex which incorrectly increments the number. But all the different variations of prefix / suffix and single number / mixed with letters make this particularly tricky.

It seems like edits need to be made to existing regexes to ensure that they are matching digit only groups. However, the above PR regex edits and the edits I've made consistently break other regexes.

Any ideas or considerations here?

@isidorn isidorn added the *out-of-scope Posted issue is not in scope of VS Code label Oct 8, 2019
@vscodebot
Copy link

vscodebot bot commented Oct 8, 2019

This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. More details here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.

If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

Thanks for your understanding and happy coding!

@vscodebot vscodebot bot closed this as completed Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug file-explorer Explorer widget issues help wanted Issues identified as good community contribution opportunities *out-of-scope Posted issue is not in scope of VS Code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants