本帖最后由 DiamondbacK 于 2016-9-3 16:05 编辑
- @echo off & setlocal
-
- call :getTable table as a string of
- :l1 "index:unit name:filename:previous unit name"'s
- call :listFiles table
- :l2
- call :requestIndex index
- if /i "%index%" == "L" goto l1 list files
- call type "%%file%index%%%" && goto l2 request again
-
- endlocal & exit /b
- -------------------------------------------------------------------------------
-
- :getTable
- set %1=
- for /f "tokens=1,3* delims==:" %%I in ('
- (
- for %%I in (*.txt^) do @(
- set "firstLine=" ^&
- set /p firstLine^=^<"%%I" ^&
- call echo %%^^firstLine%%:%%I
- ^)
- ^) ^| findstr /i "^单位名称" ^| sort ^| findstr /n "."
- ') do (
- set file%%I=%%K
- call set table=%%table%% "%%I:%%J:%%K:%%prevUnitName%%"
- set prevUnitName=%%J
- )
- goto :eof
-
- :listFiles
- for /f "tokens=1,2,3,4 delims=:" %%I in ('
- for %%I in (%table%^) do @echo :%%~I:
- ') do (
- if "%%J" neq "%%L" (
- echo=& echo 单位名称=%%J
- echo ===============================
- )
- echo %%I. %%K
- )
- goto :eof
-
- :requestIndex
- echo=& set %1=
- set /p %1=请输入文件索引号(输入"L"查看列表,无效索引自动退出):
- goto :eof
复制代码
|