多个IF else条件问题 [英] multiple IF else conditions issue

查看:139
本文介绍了多个IF else条件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,我想根据搜索项将文件分离/拆分为多个文件.
如果看到add,我想将该行放入addfile. 类似于changeprop,插入,如果找不到任何匹配项,则插入otherfile.我无法处理if else条件.

I have an issue where I want to segregate / split file based on search item into multiple files.
if I see add I want to put that line to addfile. similar to changeprop, insert and if I cannot find any match then to otherfile. I'm unable to process the if else conditions.

FOR /F "tokens=* delims=" %%a in ('TYPE "%File%"') DO (
    SET "eachline=%%a"
    IF /i "!eachline:~0,3!" == "ADD " (ECHO !eachline!>>"%ADDActionScriptsMergedFile%")
    ELSE ( IF /i "!eachline:~0,9!" == "ADDINSERT" (ECHO !eachline!>>"%ADDINSERTActionScriptsMergedFile%")
        ELSE ( IF /i "!eachline:~0,3!" == "MOV" (ECHO !eachline!>>"%MOVEActionScriptsMergedFile%")
            ELSE ( IF /i "!eachline:~0,6!" == "INSERT" (ECHO !eachline!>>"%INSERTPROPActionScriptsMergedFile%")
                ELSE ( IF /i "!eachline:~0,10!" == "CHANGEPROP" (ECHO !eachline!>>"%CHANGEPROPActionScriptsMergedFile%")
                    ELSE (ECHO !eachline!>>"%OTHERPROPActionScriptsMergedFile%")
                )
            )
        )
    )
)

推荐答案

尝试一下.它基于我的上一个答案,但是做了一些改动,以避免多次编写相同的代码(两次都可以,但现在是5(或什至更多),使用for循环很有意义):

Give this a try. It is based on my previous answer, but changed a bit to avoid writing the same code several times (two times was ok, but now, that it's 5 (or maybe even more), it makes sense to use a for loop):

@echo off
setlocal
set "File=.\WorkFlow_Action_Script_Merged_Folder\All_WorkFlows_Merged_File.txt"
set "Dest=.\WorkFlow_Action_Script_Merged_Folder\@_WorkFlows_Merged_File.txt"
for %%a in ("Add " Addinsert Mov Insert Changeprop) do (
  type "%File%" | findstr /bic:"%%~a" > "%Dest:@=%%~a%"
)
type "%File%" |findstr /bivc:"Addinsert" /bivc:"Mov" /bivc:"Insert" /bivc:"Changeprop" /bivc:"Add " > "%Dest:@=OTHERPROP%"

(未经测试,因为我没有您的文件或文件夹结构)

(untested, as I don't have your files or folderstructure)

这篇关于多个IF else条件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆