[Bash shell] 纯文本查看 复制代码@echo off
setlocal enabledelayedexpansion
rem 遍历D盘test目录下的所有文件夹
set "counter=1"
for /d %%i in (D:\test\*) do (
set "folder[!counter!]=%%i\"
set /a "counter+=1"
)
rem 将文件夹路径按照升序排列
for /l %%i in (1,1,%counter%) do (
for /l %%j in (%%i,1,%counter%) do (
set "folder1=!folder[%%i]!"
set "folder2=!folder[%%j]!"
if "!folder1!" gtr "!folder2!" (
set "folder[%%i]=!folder2!"
set "folder[%%j]=!folder1!"
)
)
)
rem 将排序后的文件夹路径写入txt文件
set "output_file=D:\test\folders.txt"
del "%output_file%" 2>nul
for /l %%i in (1,1,%counter%) do (
echo !folder[%%i]!>>"%output_file%"
)
echo "Done."