我有一个应用程序可以读取目录中的所有文件,并将重命名这些文件(如果需要)并从内部创建日志文件,但是有几个捕获....
例如,如果filename为:DIY_0000000000a.xml,则变量为DIY_0000000000a,如果文件名为:DIY_0000000000.xml,则变量为DIY_0000000000
所有这一切都有一个问题......
如果用户选择重新运行应用程序的选项2,则应用程序应将目录中的所有文件重命名为DIY_xxx_rerun.xml或DIY_xxxa_rerun.xml(现在应解释上述选项中的“_”。
我遇到的问题和我需要帮助的问题是我似乎无法使条件逻辑正确。该应用程序可以工作,但如果我在目录中混合了文件(即:DIY_0000000000a.xml,DIY_0000000000.xml和DIY_0000000000_rerun.xml,DIY_0000000000_rerun.xml),它可能只适用于一种而不是另一种。非常感谢帮助。
以下是我当前代码的摘要:
SETLOCAL EnableDelayedExpansion
:EXECUTE
::IF AN XML FILE EXISTS ADD IT TO A LOG FILE, PROMPT USER IF THEY WANT TO VIEW IT
ECHO.
ECHO =============================================
ECHO **SELECT YOUR OPTION BY USING YOUR KEYBOARD**
ECHO =============================================
ECHO.
ECHO 1 - Generate DIY Log Files for normal orders
ECHO 2 - Generate DIY Log Files for _rerun orders
ECHO 3 - EXIT
ECHO.
ECHO.
SET /P CHOICE=Type your option, then press ENTER:
IF %CHOICE%==1 (
SET RERUN=
GOTO PROCESS
)
IF %CHOICE%==2 (
SET RERUN=_rerun
GOTO PROCESS
)
IF %CHOICE%==3 EXIT
IF NOT '%CHOICE%'== SET CHOICE=%CHOICE:~0,1%
ECHO.
ECHO "%CHOICE%" is not a valid option.
PAUSE
GOTO EXECUTE
:PROCESS
IF EXIST DIY*.xml (
SET /a FILECOUNTER=0
ECHO.
ECHO Processing...
FOR /f "delims=" %%a IN ('DIR /b /a-d /on DIY*.xml') DO (
SET /a LOGCOUNTER=!FILECOUNTER!/1+1
SET ORDERNUMBER=%%a
IF "!ORDERNUMBER:~14,1!" NEQ "." (
IF "!ORDERNUMBER:~14,1!" NEQ "_" (
SET ORDERNUMBSTR=!ORDERNUMBER:~0,15!
) ELSE (
SET ORDERNUMBSTR=!ORDERNUMBER:~0,14!
)
)
SET ORDERNUMBSTR=!ORDERNUMBER:~0,14!
IF "%RERUN%"=="_rerun" (
REN !ORDERNUMBSTR!.xml !ORDERNUMBSTR!%RERUN%.xml >NUL 2>&1
) ELSE (
REN *!ORDERNUMBSTR!*.xml !ORDERNUMBSTR!.xml >NUL 2>&1
)
FOR /f "tokens=4 delims=<>" %%i IN ('TYPE !ORDERNUMBSTR!%RERUN%.xml ^|find "DIY_LOG_ID"') DO (
SET DIYLOGID=%%i
)
FOR /f "tokens=7 delims=<>" %%j IN ('TYPE !ORDERNUMBSTR!%RERUN%.xml ^|find "ACCOUNT_KEY"') DO (
SET ACCOUNTKEY=%%j
FOR /f "tokens=1-3 delims=-" %%x IN ("!ACCOUNTKEY!") DO (
SET CONTRACTNR=%%x
SET PLANSEQ=%%y
SET SUBSEQ=%%z
)
)
...
ENDLOCAL
答案 0 :(得分:0)
只需要一天时间考虑一下......
能够通过使用以下FOR循环而不是IF来获得我想要的东西
FOR /f "delims=" %%a IN ('DIR /b /a-d /on DTL*.XML') DO (
SET /a LOGCOUNTER=!FILECOUNTER!/1+1
SET ORDERNUMBER=%%a
**FOR /f "tokens=1,2 delims=_." %%p IN ("!ORDERNUMBER!") DO (
SET ORDERNUMBSTR=%%p_%%q**
)
IF "%RERUN%"=="_rerun" (
REN !ORDERNUMBSTR!.XML !ORDERNUMBSTR!%RERUN%.XML >NUL 2>&1
) ELSE (
REN *!ORDERNUMBSTR!*.XML !ORDERNUMBSTR!.XML >NUL 2>&1
)
...