[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
可以试试用powershell
版本5.1以上
  1. Add-Type -TypeDefinition @"
  2. using System.Runtime.InteropServices;
  3. namespace the{
  4. public static class sort{
  5.     [DllImport("Shlwapi.dll", CharSet = CharSet.Unicode)]
  6.     public static extern int StrCmpLogicalW(string psz1, string psz2);
  7. }}
  8. "@
  9. class exsort:System.Collections.IComparer{
  10. [int]Compare($a,$b){return [the.sort]::StrCmpLogicalW($a,$b)}
  11. }
  12. $a=gci -file -n
  13. [array]::sort($a,[exsort]::new())
  14. (0..($a.Length-1)).ForEach({rni -LiteralPath ($a[$_]) ([string]::format("{0:d4}",$_+1))})
复制代码

TOP

回复 13# Nsqs


啊,因为那代码是直接在powershell窗口里输入执行的
脚本文件执行的话试试下面的(加上了打印,方便测试,不过修改名字时还是不包含拓展名)
还有较高版本的系统不知道行不行
  1. #@&cls&powershell -sta "$self='%~nx0';type -literalpath '%~f0'|out-string|iex"&pause&exit/b
  2. Add-Type -TypeDefinition @"
  3. using System.Runtime.InteropServices;
  4. namespace the{
  5. public static class sort{
  6.     [DllImport("Shlwapi.dll", CharSet = CharSet.Unicode)]
  7.     public static extern int StrCmpLogicalW(string psz1, string psz2);
  8. }}
  9. "@
  10. class exsort:System.Collections.IComparer{
  11. $st=0
  12. exsort($t){$this.st=$t}
  13. [int]Compare($a,$b){return $this.st::StrCmpLogicalW($a,$b)}
  14. }
  15. $a=gci -file -n -exclude ($MyInvocation.MyCommand.Name,$self)
  16. [array]::sort($a,[exsort]::new([the.sort]))
  17. (0..($a.Length-1)).ForEach({
  18. [console]::writeline("$($a[$_])        rename to        "+[string]::format("{0:d4}",$_+1))
  19. #rni -LiteralPath ($a[$_]) ([string]::format("{0:d4}",$_+1))
  20. })
复制代码

TOP

返回列表