回复 4# zhoubin
再给一个匹配不同目录级数(绝对路径)的通用版本...
核心代码如下》调整代码第二行中的数字 4 即为目录级数- @echo off &setlocal enabledelayedexpansion
- set "p=.:[^\\]*" &for /l %%n in (1,1,4) do set "p=!p!\\[^^\\]*"
- dir/b/s/ad|findstr "!p!$"
- endlocal&pause&exit/b
复制代码 示例代码如下》- @echo off &setlocal enabledelayedexpansion
- echo,第2级
- set "p=.:[^\\]*" &for /l %%n in (1,1,2) do set "p=!p!\\[^^\\]*"
- dir/b/s/ad|findstr "!p!$"
- echo,第3级
- set "p=.:[^\\]*" &for /l %%n in (1,1,3) do set "p=!p!\\[^^\\]*"
- dir/b/s/ad|findstr "!p!$"
- echo,第4级
- set "p=.:[^\\]*" &for /l %%n in (1,1,4) do set "p=!p!\\[^^\\]*"
- dir/b/s/ad|findstr "!p!$"
- endlocal&pause&exit/b
复制代码
|