我需要从目录中的多个文件替换空白行。我可以为单个文件执行此操作,但我无法对文件夹中的多个文件执行此操作。
这是适用于单个文件的代码
@echo off
for /F "tokens=* delims=" %%A in (input.txt) do echo %%A >> output.txt
请帮我解决这个问题,因为我是批量编程的新手
答案 0 :(得分:1)
感谢发布代码行,我一直在寻找并且有点急于自己推理:)
要将其用于一系列文件,您可以执行以下操作:(您可以将整个代码复制到单个批处理文件中)
:: Say you have several files named Input1.txt, Input2.txt, Input3.txt, etc
:: this will call a subroutine within the same batch file, called :Strip
:: using each file as parameter:
for %%A in ("input*.txt") do call :Strip %%A
Goto End
:Strip
:: The subroutine starts here
:: First we take the name of the input file and use it to generate
:: the name of an output file, Input1.txt would output to output_(Input1).txt, etc
For %%x in (%*) do set OutF=output_(%%~nx).txt
:: I now erase the output file it it already exists, so if you run this twice
:: it won't duplicate output
del %OutF%
:: Now comes the line you already supplied
for /F "tokens=* delims=" %%B in (%*) do echo %%B >> %OutF%
:: and now we return from the subroutine
Goto :EOF
:End