Batch file 批处理脚本:将.txt列表中的内容合并到一个文件中

Batch file 批处理脚本:将.txt列表中的内容合并到一个文件中,batch-file,batch-processing,Batch File,Batch Processing,在Windows 10上,我有一个.bat: @echo off for /f "delims=" %%i in (filelist.txt) do ( echo %%~nxi >> output.txt type "%%~ni*" >> output.txt echo. >> output.txt echo. >> output.txt ) Exit 现在它的作用是: 读取filelist.txt,其中包含.txt文件的名称,如: 2018

在Windows 10上,我有一个.bat

@echo off

for /f "delims=" %%i in (filelist.txt) do (
echo %%~nxi >> output.txt
type "%%~ni*" >> output.txt
echo. >> output.txt
echo. >> output.txt
)
Exit
现在它的作用是:

  • 读取filelist.txt,其中包含.txt文件的名称,如: 201808173105(不带“.txt”
  • 搜索这些文件:201808173105.txt
  • 将文件名(不带“.txt”)复制到output.txt中
  • 插入文件的内容
  • 插入两个空行
  • 对filelist.txt中命名的所有文件重复整个过程
  • -->它工作正常!(或者您是否看到任何可能出现故障的异常情况?)
这将根据列表插入文本文件的完整内容。 我可以修改它吗

  • 不是.txt的全部内容,而是只插入其中的一部分? 例如,从“title:”之后到
    @echo off之前的所有内容
    2> output.txt echo。
    @>&3 (
    回显调试信息
    回音-----------------
    )
    对于(filelist.txt)中的/f“delims=“%%A”do(
    对于(“%%~nA*”)中的%%B,执行调用:读取“%%~B”
    )>>output.txt
    退出/b
    :读
    setlocal
    设置“行=”
    回波(%~nx1)
    对于/f“usebackq delims=“%%C in(“%1”)do(
    设置“行=%%C”
    对于('call echo'%%行:~0,4%%')中的/f“tokens=*”%%D,请执行以下操作(
    
    @>&3 echo文件:“%$1”测试:%%D==”如果我的问题不清楚,我很抱歉,我既不是英语母语人士,也不是编程人员。谢谢!它很有效!我不知道“>”和“!”可能会引起麻烦。它看起来真的很复杂。我怀疑我能在所有这些“for”循环中很快得到它。也谢谢你的解释!
    #201508081213
    ###201609101219
    
    #201508081213
    TEXT
    ###201609101219
    TEXT
    
    @echo off
    
    2> output.txt echo.
    
    @>&3 (
        echo Debug Information
        echo -----------------
    )
    
    for /f "delims=" %%A in (filelist.txt) do (
        for %%B in ("%%~nA*") do call :read "%%~B"
    ) >> output.txt
    
    exit /b
    
    :read
    setlocal
    set "line="
    
    echo(%~nx1
    
    for /f "usebackq delims=" %%C in ("%~1") do (
        set "line=%%C"
    
        for /f "tokens=*" %%D in ('call echo "%%line:~0,4%%"') do (
            @>&3 echo File: "%~1"  Test: %%D == "<!--"
            if %%D == "<!--" (
                @>&3 echo Found: "<!--"
                echo.
                echo.
                exit /b 0
            )
        )
    
        call echo(%%line%%
    )
    
    echo.
    echo.
    exit /b 0