找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 28322|回复: 5

[文件操作] [已解决]用批处理检查文件名数字名问题?

[复制链接]
发表于 2019-11-20 21:37:20 | 显示全部楼层 |阅读模式
本帖最后由 czvde 于 2019-11-21 19:33 编辑

文件夹里面的文件:
IMG_001.pdf
IMG_003.pdf
………………
IMG_100.pdf

批处理效果
abc.txt文本内容如下:
IMG_002.pdf

问题已解决
发表于 2019-11-21 09:24:33 | 显示全部楼层
IMG01_002
IMG01_396
上面这两个怎么来的
发表于 2019-11-21 12:04:18 | 显示全部楼层
本帖最后由 flashercs 于 2019-11-21 18:47 编辑
  1. <#*,:&cls
  2. @echo off
  3. pushd "%~dp0"
  4. Powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath "%~0" -ReadCount 0 | Out-String ))) "
  5. popd
  6. pause
  7. exit /b
  8. #>
  9. $hash = @{ }
  10. Split-Path -Path (Convert-Path -Path *_*) -Leaf | ForEach-Object {
  11.   if ((Test-Path -LiteralPath $_ -PathType Leaf) -and ($_ -match '^([^_]+_)(\d+)')) {
  12.     if (-not $hash.ContainsKey($Matches[1])) {
  13.       $hash.Add($Matches[1], (New-Object 'System.Collections.Generic.List[int]'))
  14.     }
  15.     $hash.Item($Matches[1]).Add($Matches[2] -as [int])
  16.   }
  17. }
  18. $hash.GetEnumerator() | ForEach-Object {
  19.   $iList = $_.Value
  20.   $iList.Sort()
  21.   $ii = $iList.Item($iList.Count - 1) -as [int]
  22.   for ($i = 1; $i -le $ii; $i++) {
  23.     if (-not $iList.Contains($i)) {
  24.       '{0}{1}' -f $_.Key, ([string]$i).PadLeft(3, [char]'0')
  25.     }
  26.   }
  27. } | Set-Content .\abc.txt
复制代码

评分

参与人数 1技术 +1 收起 理由
czvde + 1 谢谢

查看全部评分

 楼主| 发表于 2019-11-21 17:38:23 | 显示全部楼层
本帖最后由 czvde 于 2019-11-21 19:33 编辑

回复 2# terse


问题已解决
 楼主| 发表于 2019-11-21 18:05:10 | 显示全部楼层
本帖最后由 czvde 于 2019-11-21 19:34 编辑

回复 3# flashercs



感谢!
发表于 2019-11-21 18:48:41 | 显示全部楼层
回复 5# czvde


    修改了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-19 11:36 , Processed in 0.019223 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表