所以我有一个包含数百个OCR输出文本文件的文件夹。我正在尝试制作一个批处理文件,它会在每个文件的开头附加文件名。
到目前为止,我一直查看并在stackoverflow上找到此代码,但它在每行的开头附加了文件名。 Appending the filename beginning of each line
@echo off
if "%~1" equ ":FindFiles" goto :FindFiles
cd "C:\Users\Neha\Desktop\GB PRoducts\OCR\test"
:: Append newline to text files that are missing newline on last line
for /f "eol=: delims=" %%F in ('"%~f0" :FindFiles') do echo(>>"%%F"
:: Merge the text files and prefix each line with file name
findstr "^" *.txt >output.log
exit /b
:FindFiles
setlocal enableDelayedExpansion
:: Define LF to contain a newline character
set lf=^
:: The above 2 blank lines are critical - do not remove
:: List files that are missing newline on last line
findstr /vm "!lf!" *.txt
答案 0 :(得分:1)
type *.txt>x.x 2>&1
(type
将文件名写入STDERR,文件内容写入STDOUT。>output.log 2>&1
将STDOUT写入文件,将STDERR写入同一目的地。)
或
for %%a in (*.txt) do (echo %%a&type "%%a")