我有一个像这样的文件目录:
PDEN51505_1_1_N611729_15894285.XML
PDEN51505_1_2_N611729_15894286.XML
PDEN51505_2_1_N599021_15746279.XML
我需要为这些文件创建一个自定义日志文件,最终看起来像这样:
462121 14105618 PD EN 97240 1 97240 RF PDEN51505_1_1_N611729_15894285 XML C N N 0
462121 14105618 PD EN 97240 1 97240 RF PDEN51505_1_2_N611729_15894286 XML C N N 0
462121 14105618 PD EN 97240 1 97240 RF PDEN51505_2_1_N599021_15746279 XML C N N 0
我不是每次都修改自定义日志文件中的各个行,而是创建一个自动化过程来为我构建它。这是我到目前为止所拥有的:
@ECHO OFF
SETLOCAL EnableDelayedExpansion
MODE con: cols=125 lines=50
SET /P WHERE=Where are the XMLs located (full file path)? (default: %CD%)
IF "%WHERE%"=="" (
SET WHERE=%CD%\
) ELSE (
IF "!WHERE:~-1!"=="\" (
SET WHERE=!WHERE!
) ELSE (
SET WHERE=!WHERE!\
)
)
:: TRAVERSE TO DIRECTORY THE USER JUST INPUT
CD %WHERE%
:: CREATES AN TEMP OUTPUT FILE OF THE DIRECTORY (MINUS EXTENTIONS)
FOR /f "tokens=*" %%a in ('dir /b /a-d *.xml') DO ECHO %%~na>>output.txt
:: CLEARS OUT "PDEN" VARIABLES
FOR /f "delims==" %%i IN ('set PDEN 2^>nul') DO (SET %%i=)
:: CREATES A LISTING SEPERATED BY SPACES
FOR /f "tokens=*delims=_" %%a IN (output.txt) DO (
SET PDEN=!PDEN! %%a
)
:: ATTEMPTS TO GENERATE A LOG FILE
FOR /f "tokens=*delims=" %%i IN ('set PDEN 2^>nul') DO (
>%WHERE%PDEN_GEN_LOG.log ECHO 462121 14105618 PD EN 97240 1 97240 RF !PDEN! XML C N N 0
ECHO [INFO] Generated PDEN_GEN_LOG.log
)
:: PROMPTS USER IF THEY WANT TO SEE THEIR CREATION
ECHO FINISHED
ECHO A new control file has been saved to %WHERE%
SET /P FILESURE=Would you like to view the LOG file you created?(Y/[N])?
IF /I "%FILESURE%" NEQ "Y" GOTO REMOVE
notepad.exe %WHERE%PDEN_GEN_LOG.log
:: REMOVES THE OUTPUT.TXT FILE
:REMOVE
RM %WHERE%output.txt
exit
它做所有事情直到创建点。它采用之前在 output.txt 中生成的列表并将其放在一行中,所以现在我的日志文件看起来像这样:
462121 14105618 PD EN 97240 1 97240 RF PDEN51505_1_1_N611729_15894285 PDEN51505_1_2_N611729_15894286 PDEN51505_2_1_N599021_15746279 XML C N N 0
最重要的是,每次我执行时 %PDEN% 似乎都会变大。我需要刷新那个变量吗?
把招工广告!
谢谢大家