Board logo

标题: [文本处理] [已解决]批处理如何查询当前目录下文件名是否包含某些字符,并输出? [打印本页]

作者: younger0108    时间: 2014-9-16 17:50     标题: [已解决]批处理如何查询当前目录下文件名是否包含某些字符,并输出?

本帖最后由 younger0108 于 2014-9-17 11:05 编辑

比如字符为A1
想查询当前目录下的所有文件(没有子文件夹),是否有文件名中包含A1的文件,如果没有则输出A1
作者: Linuxer    时间: 2014-9-16 18:12

本帖最后由 Linuxer 于 2014-9-16 18:18 编辑
  1. @echo off
  2. dir /b | findstr "A1" 1>nul
  3. if %errorlevel% equ 1 echo A1
  4. if %errorlevel% equ 0 echo 存在包含A1的文件
  5. pause>nul
复制代码

作者: Batcher    时间: 2014-9-16 19:00

回复 2# Linuxer


建议使用 if ... else ... 的格式
  1. @echo off
  2. dir /b | findstr "A1" 1>nul
  3. if %errorlevel% equ 0 (
  4.     echo 存在包含A1的文件
  5. ) else (
  6.     echo A1
  7. )
  8. pause
复制代码

作者: Linuxer    时间: 2014-9-17 10:51

回复 3# Batcher


    哦,学习了,这样只需要if一次errorlevel。
作者: younger0108    时间: 2014-9-17 11:05

回复 3# Batcher


    学习了,谢谢。可以用




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