2012-08-25 87 views
0

我需要替換目錄中多個文件的空行。我可以爲單個文件執行此操作,但我無法爲文件夾中的多個文件執行此操作。如何刪除目錄中多個文件的空行

這是單個文件的工作代碼

@echo off 
for /F "tokens=* delims=" %%A in (input.txt) do echo %%A >> output.txt 

請幫我這是我絕對新的批量編程

回答

1

感謝張貼的代碼THA行,我一直在尋找只是這一點,並有點急於自己推理:)

要使用它的一系列文件,喲可以做到以下幾點:(你可以複製整個代碼到一個單一的批處理文件)

:: 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