如何以相反的顺序启动cmd批处理循环? (带有最后一个目录) [英] How to start cmd batch loop in reversed order? (with the last directory)

查看:74
本文介绍了如何以相反的顺序启动cmd批处理循环? (带有最后一个目录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作目录如下:

  • C:\ Workdir \ Dir1
  • C:\ Workdir \ Dir2
  • C:\ Workdir \ Dir3

我正在使用此循环启动批处理文件:

i am starting a batchfile with this loop:

for /D %%a in (*) do (

,然后我的实际命令使每个目录一个接一个地前进. 但是我需要开始逆转.从最后一个目录开始,然后向上工作.从Dir3开始,然后是Dir2,然后是Dir1 我该怎么办?

and then my actual command progresses each directory one after another. but i need to start the progressing reversed. by starting with the last directory and then working upwards. starting with Dir3 and then Dir2 and then Dir1 how do i do that?

推荐答案

您应使用"for/f"循环,然后通过"dir"命令以相反的顺序列出所有文件夹.

You should loop using "for /f" and then list all folders in the reverse order via the "dir" command.

@echo off
for /f "tokens=*" %%G in ('dir /s /b /A:D /O:-N "%CD%"') do (
    echo %%G
)

位置:

  • %CD% - is current directory - same if you call "in (*)" from the same directory
  • /O:-N is reverse order by name
  • https://ss64.com/nt/dir.html
  • https://ss64.com/nt/for_d.html

这篇关于如何以相反的顺序启动cmd批处理循环? (带有最后一个目录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆