Board logo

标题: [文件操作] 批处理如何批量在文件名指定位置加入字符? [打印本页]

作者: silenthot    时间: 2018-7-28 20:18     标题: 批处理如何批量在文件名指定位置加入字符?

比如文件夹下有文件:
C060101.JPG
C060102.JPG
C060103.JPG
C060104.JPG
C060105.JPG
需要批量在第5位后添加字符A,添加后效果为:
C0601A01.JPG
C0601A02.JPG
C0601A03.JPG
C0601A04.JPG
C0601A05.JPG
求大神指点~
作者: yhcfsr    时间: 2018-7-29 11:30

  1. @echo off&mode con cols=73 lines=20
  2. ::添加的字符串
  3. set "str=A"
  4. ::设置位置
  5. set "pot=5"
  6. for /r %%a in (*) do if "%%~xa" neq ".bat" (
  7. set "var=%%~nxa"
  8. setlocal enabledelayedexpansion
  9. set "var1=!var:~,%pot%!"
  10. set "var2=!var:~%pot%!"
  11. ren "%%a" "!var1!%str%!var2!
  12. endlocal
  13. )
  14. pause
复制代码

作者: silenthot    时间: 2018-7-30 15:47

回复 2# yhcfsr


    厉害厉害!谢谢!




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2