用户登录
用户注册

分享至

BAT:通过连接符处理判断OR的关系

  • 作者: Heiy
  • 来源: 51数据库
  • 2020-08-06

使用情况说明:

适用于对某个文件夹下不同的文件夹(名称)做不同的处理,但存在需要对其中多个文件夹(名称)进行相同处理的情况

例子中的目录结构:

.\1.2.3 -- 文件夹
.\a.b.c -- 文件夹
.\d.d.d -- 文件夹
.\if_or.bat -- 文件

@echo off
set current_path=%~dp0
echo %current_path%

for /f "delims=" %%i in ('dir /ad/b "%current_path%"') do (
    set temp_path=%%i
    setlocal enabledelayedexpansion
    rem find /C --仅显示包含字符串的行数。--找不到返回1,找到返回0
    echo !temp_path! | find /c "a.b." > nul || echo !temp_path! | find /c "1.2." > nul
    ::echo !temp_path! | find /c "a.b." > nul
    echo =!temp_path!=!errorlevel!
    if !errorlevel! equ 0 (
        echo It is included !temp_path!
        
        echo !temp_path! | find /c "1.2." > nul
        echo -!temp_path!-!errorlevel!
        if !errorlevel! equ 0 (
            echo success 1.2.
        )
        echo !temp_path! | find /c "a.b." > nul
        echo -!temp_path!-!errorlevel!
        if !errorlevel! equ 0 (
            echo success a.b.
        )
    ) else (
        echo Not match !temp_path!
    )
    setlocal disabledelayedexpansion
)
echo =======================================================
pause
软件
前端设计
程序设计
Java相关