本帖最后由 flashercs 于 2019-11-21 18:47 编辑
- <#*,:&cls
- @echo off
- pushd "%~dp0"
- Powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
- popd
- pause
- exit /b
- #>
- $hash = @{ }
- Split-Path -Path (Convert-Path -Path *_*) -Leaf | ForEach-Object {
- if ((Test-Path -LiteralPath $_ -PathType Leaf) -and ($_ -match '^([^_]+_)(\d+)')) {
- if (-not $hash.ContainsKey($Matches[1])) {
- $hash.Add($Matches[1], (New-Object 'System.Collections.Generic.List[int]'))
- }
- $hash.Item($Matches[1]).Add($Matches[2] -as [int])
- }
- }
- $hash.GetEnumerator() | ForEach-Object {
- $iList = $_.Value
- $iList.Sort()
- $ii = $iList.Item($iList.Count - 1) -as [int]
- for ($i = 1; $i -le $ii; $i++) {
- if (-not $iList.Contains($i)) {
- '{0}{1}' -f $_.Key, ([string]$i).PadLeft(3, [char]'0')
- }
- }
- } | Set-Content .\abc.txt
复制代码
|