Board logo

标题: [文本处理] 批处理怎样在循环里截取字符串并保存? [打印本页]

作者: 海面嘎    时间: 2022-1-21 11:33     标题: 批处理怎样在循环里截取字符串并保存?

set newestFile
set fileList=m-101-1.txt m-103-1.txt m-102-1.txt
遍历fileList,根据中间的三位数字,把最大的文件名保存在newestFile
作者: Batcher    时间: 2022-1-21 14:02

回复 1# 海面嘎


请参考Q-04把bat文件保存为ANSI编码:
https://mp.weixin.qq.com/s/6lbb97qUOs1sTyKJfN0ZEQ
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "max=0"
  4. set "fileList=m-101-1.txt m-103-1.txt m-102-1.txt"
  5. for %%a in (%fileList%) do (
  6.     for /f "tokens=1-3 delims=-" %%b in ("%%a") do (
  7.         if %%c gtr !max! (
  8.             set "max=%%c"
  9.         )
  10.         set "newestFile=%%b-!max!-%%d"
  11.     )
  12. )
  13. echo,!newestFile!
  14. pause
复制代码





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