@echo off&setlocal enabledelayedexpansion
cd .>ok.txt
for /f "delims=" %%a in ('dir /a-d /b *.txt') do (
set out=1
if /i not "%%~nxa"=="ok.txt" (
for /f "usebackq delims=" %%b in ("%%~a") do (
set "line=%%a"
if defined out (
echo %%a >>ok.txt
set out=
)
)
)
echo !line! >>ok.txt
)
提取当前文件夹下文本文件的第一行和最后 一行,输出到ok.txt,
追问这个我试了,没成功,只提取了文件名,并没有提取到文本内容,谢谢
追答@echo off&setlocal enabledelayedexpansion
cd .>ok.txt
for /f "delims=" %%a in ('dir /a-d /b *.txt') do (
set out=1
if /i not "%%~nxa"=="ok.txt" (
for /f "delims=" %%b in ('findstr /r /c:"[^ ]" "%%~a"') do (
set "line=%%b"
if defined out (
echo %%a >>ok.txt
set out=
)
)
)
echo !line! >>ok.txt
)
难道连第一行都没提取到,刚才只是把最后一行的代码写错了