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