按逐行数字顺序对列表进行排序 [英] Sorting a list in progressive numeric order

查看:181
本文介绍了按逐行数字顺序对列表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例文件列表:


  • 1.jpg
  • 3.jpg

  • 22.jpg



在(* .jpg)中迭代列表

  for / r%j do @echo%〜nxj 
<


给出以下结果: $ c> 1
2
22
3

  1 
2
3
22

感谢大家

解决方案 @ECHO Off
SETLOCAL ENABLEDELAYEDEXPANSION
SETsourcedir = U:\sourcedir

FOR / f %% a IN('dir / b / ad'%sourcedir%\ * .jpg'')DO(
SET / a seq = 1000000000 + %%〜na
ECHO!seq!)
)>%temp%\tempfile

FOR / f %% a IN('sort'%temp%\tempfile'')DO
SET / a seq = %% a-1000000000
ECHO!seq!.jpg)


GOTO:EOF

这应该适合你 - 当然,你需要设置你自己的 sourcedir ,临时文件名取决于你,它没有被清理并且它只能用纯数字文件名而不用前导零<1000000000。假定 .jpg 扩展名。


Example file list:

  • 1.jpg
  • 2.jpg
  • 3.jpg
  • 22.jpg

easy cycle for iterating the list

for /r %j in (*.jpg) do @echo %~nxj

The gives the following result:

1
2
22
3

How can i order the results consecutively, like below?

1
2
3
22

thanks everyone

解决方案

@ECHO Off
SETLOCAL ENABLEDELAYEDEXPANSION
SET "sourcedir=U:\sourcedir"
(
FOR /f %%a IN ('dir /b /a-d "%sourcedir%\*.jpg" ') DO (
  SET /a seq=1000000000+%%~na
  ECHO !seq!) 
)>"%temp%\tempfile"

FOR /f %%a IN ('sort "%temp%\tempfile"') DO (
 SET /a seq=%%a-1000000000
  ECHO !seq!.jpg) 
)

GOTO :EOF

This should work for you - of course, you'd need to set your own sourcedir, the temp filename is up to you, it's not cleaned up and it will only work with pure-numeric filenames without leading zeroes <1000000000. The .jpg extension is assumed.

这篇关于按逐行数字顺序对列表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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