windows - 以相反顺序循环目录中的文件

标签 windows batch-file command-prompt

在 DOS 批处理文件中,我可以编写以下循环以按字母升序迭代目录中的文件:

for %f in (*) do (echo %f)

我如何做同样的事情,但以相反的顺序(字母降序)迭代文件?

最佳答案

从命令行:

for /f "tokens=*" %f in ('dir /b /o-n') do (echo %f)

在一个 bat 文件中:

for /f "tokens=*" %%f in ('dir /b /o-n') do (echo %%f)

/B           Uses bare format (no heading information or summary).
/O           List by files in sorted order.
sortorder    N  By name (alphabetic)
             -  Prefix to reverse order

Type "dir /?" in CMD for more details

关于windows - 以相反顺序循环目录中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18818295/

相关文章:

c++ - 可以从外部进程移动/调整窗口大小 [C++/Windows]

java - 文件路径中斜杠和反斜杠的奇怪行为

batch-file - CMD命令删除文件并将其放入回收站?

windows - 如何从不同目录的其他批处理文件中的批处理文件启动 exe 文件?

windows - 如何在 Windows 中使用命令提示符在不同的端口而不是 8080 上启动 jenkins?

r - 从 R 调用批处理文件时路径中存在空格问题

C、MS Windows系统创建临时文件

windows - Powershell 中的流水线字符串

java - 执行批处理文件错误 : "Could not find or load main class"

python - 打印到屏幕时修改字体大小