怎么用bat脚本批量读取一个文件夹中的所有txt?

2025-03-22 17:49:19
推荐回答(2个)
回答1:

@echo off &setlocal ENABLEDELAYEDEXPANSION
cls
set /p file=请把要读取文本文档的文件夹拖入本窗口       
set /p output=请输入要生成文件的名称
for %%i in (%output%)do (
if "%%~si"=="" msg * 文件格式不对 &%0
if not "%%~xi"==".txt" msg * 文件后缀不对 -_-!!!&%0
)
if not exist %file% %0
if exist %output% del /s /q /f %output% >nul 2>nul
set id=0
for /f "tokens=*" %%i in ('dir /s /b %file%\*.txt') do (
set id+=1
set !id!=%%i
)
for /l %%i in (1,1,%id%) do (
for /f "tokens=*" %%b in (!%%i!) do (
echo %%b>>%output%
)

notepad %output%

回答2:

我只知道怎么用r语言读取