在批处理文件中按名称排序 [英] Sort by name in batch file

查看:689
本文介绍了在批处理文件中按名称排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按版本命名的.sql文件列表

I have a list of .sql files named by version

EG:
5.1.9.5.sql
5.2.1.5.sql
5.5.1.7.sql
5.10.6.2.sql

EG:
5.1.9.5.sql
5.2.1.5.sql
5.5.1.7.sql
5.10.6.2.sql

但是在使用以下方法遍历它们时:

But when looping over them using:

for %%i in (*.sql) do (
    echo %%i
)

它们以以下顺序出现:
5.1.9.5.sql
5.10.6.2.sql
5.2.1.5.sql
5.5.1.7.sql

They come out in the following order:
5.1.9.5.sql
5.10.6.2.sql
5.2.1.5.sql
5.5.1.7.sql

有什么办法可以使它们按照Windows的文件系统中第一个列出的顺序出现?无需重命名所有文件.

Is there any way to get them to come out in the order listed first, which is like the windows file system? Without having to rename all the files.

推荐答案

我设法通过按创建日期对文件进行排序来对问题进行排序.

I managed to sort the problem by sorting the files by creation date.

for /f %%i in ('dir /b /o:d *.sql') do (
    echo %%i
)

这篇关于在批处理文件中按名称排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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