Board logo

标题: [文件操作] 求批处理 取文本指定行中间的内容做文件名 [打印本页]

作者: leotang    时间: 2018-7-31 10:45     标题: 求批处理 取文本指定行中间的内容做文件名

求批处理 取文本第58行中间的内容做文件名
很多*.ccb文本文件

57行<array>

58行<string>9121_rd2_stand_3_1.png</string>

59行<string>ccbt。。。。。。</string>

取58行“9121_rd2_stand_3_1”做文件名
作者: Batcher    时间: 2018-7-31 11:04

  1. @echo off
  2. for /f "skip=57 tokens=2 delims=<>" %%i in ('type "1.ccb"') do (
  3.     set "file=%%i"
  4.     goto :ChangeName
  5. )
  6. :ChangeName
  7. ren "1.ccb" "%file%"
复制代码

作者: leotang    时间: 2018-7-31 11:14

回复 2# Batcher


    有很多.ccb文件需要修改  包括子目录
这个怎么写呢 老大
作者: yhcfsr    时间: 2018-7-31 14:19

本帖最后由 yhcfsr 于 2018-7-31 14:23 编辑
  1. @echo off
  2. for /r %%a in (*.ccb) do call :rename_file "%%a" "%%~xa"
  3. pause&goto :eof
  4. :rename_file (file,ext)
  5. setlocal
  6. for /f "skip=57 tokens=2 delims=<>" %%a in ('type "%~1"') do (
  7. set "new_name=%%~na"
  8. goto :break
  9. )
  10. :break
  11. ren "%~1" "%new_name%%~2"
  12. endlocal&goto :eof
复制代码





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