无法按排序顺序获取子文件夹

时间:2018-02-22 14:57:55

标签: batch-file cmd directory subdirectory

我们使用了部署cmd文件 dir /s /od /b Current\*.sql 它工作正常直到99.sql但是当我们引入100.sql时,100.sql在99.sql之前运行如何更正排序顺序?在99.sql之后创建100.sql所以/ od应该在100.sql之前列出99.sql。 所以帮助我如何获得正确的订单。

enter image description here

2 个答案:

答案 0 :(得分:1)

绝对最简单的方法是对所有数字进行零填充,即61变为0061,但这也需要对旧文件执行此操作。

如果失败,您可以自然地对文件进行排序;这里似乎有一个答案。 Naturally Sort Files in Batch

答案 1 :(得分:0)

尝试

for /f "delims=" %%a in ('dir /b /od /ad "current*"') do if exist "current\%%a\*.sql" dir /s /b /od "current\%%a\*.sql" 

这应首先在日期顺序(current)中扫描/ad目录名(/od),然后查找匹配"当前*名称的文件**。sql&#34 ;并列出是否存在。