bat脚本
@echo off
setlocal enabledelayedexpansion
REM 切换代码页到 UTF-8
chcp 65001 >nul
REM 设置要遍历的目录
set "rootDir=D:\Data\影像文件\MR"
REM 设置输出文件路径
set "outputFile=D:\Data\影像文件\output.txt"
REM 清空输出文件
if exist "%outputFile%" del "%outputFile%"
REM 遍历目录并写入到输出文件中
for /d /r "%rootDir%" %%d in (*) do (
set "foundFile="
for %%f in ("%%d\*") do (
if not defined foundFile (
echo %%d >> "%outputFile%"
set "foundFile=1"
)
)
)
echo 遍历完成,结果已写入到 %outputFile%
endlocal
pause