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

【建議】文件名排序方式我認爲需要改一下 #14

Open
luiguangguan opened this issue Sep 13, 2024 · 3 comments
Open

【建議】文件名排序方式我認爲需要改一下 #14

luiguangguan opened this issue Sep 13, 2024 · 3 comments

Comments

@luiguangguan
Copy link

以下是同一組文件在Windows中的排序和在rename中的排序

Windows

image

rename

image

@luiguangguan
Copy link
Author

function naturalSort(arr: string[]): string[] {
  return arr.sort((a, b) => {
    // 提取 a 和 b 中的所有數字
    const numsA = a.match(/\d+/g)?.map(Number) || [];
    const numsB = b.match(/\d+/g)?.map(Number) || [];
    
    // 比較提取的數字
    for (let i = 0; i < Math.min(numsA.length, numsB.length); i++) {
      if (numsA[i] !== numsB[i]) {
        return numsA[i] - numsB[i];
      }
    }
    
    // 如果提取的數字部分相等,則比較數字的數量(長度)
    return numsA.length - numsB.length;
  });
}

这样实现?

@JasonGrass
Copy link
Owner

重命名的目的之一,就是将这些长度不一的文件名,变成一样的长度。

用另一个方式处理了这个问题:添加修改之后的文件名的排序(预览的排序),可以检查最终生成的结果,是否满足排序要求。

image

@luiguangguan
Copy link
Author

哦,是个不错的操作,我没想到,多谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants