码迷,mamicode.com
首页 > 编程语言 > 详细

DIR 按文件名中数字大小进行排序

时间:2016-11-17 01:52:12      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:log   enum   name   http   lis   pat   enable   echo   end   

@echo off
set arg=%1
if "%arg%" == "" set arg=*
if "%arg%" == "-h" (
  echo sort by numbers in filename 
  echo usage: nsort [drive:][path][filename]
  exit /b
)

setlocal EnableExtensions
for /F "delims=" %%I in (‘dir %arg% /A-D /B /ON 2^>nul‘) do call :AddToFileList "%%I"
for /F "tokens=1* delims==" %%I in (‘set FileList[ 2^>nul‘) do echo %%J
endlocal
exit /B

:AddToFileList
set "FileName=%~n1"
if "%FileName%" == "" set "FileName=%~x1"
set "FileNumber="

:GetFileNumber
for /F "delims=0123456789" %%I in ("%FileName:~-1%") do goto AddFileToArray
set "FileNumber=%FileName:~-1%%FileNumber%"
set "FileName=%FileName:~0,-1%"
if not "%FileName%" == "" goto GetFileNumber

:AddFileToArray
set "FileNumber=00000%FileNumber%"
set "FileNumber=%FileNumber:~-5%"
set "FileList[%FileName%_%FileNumber%]=%~1"
goto :EOF
nsort.7z

DIR 按文件名中数字大小进行排序

标签:log   enum   name   http   lis   pat   enable   echo   end   

原文地址:http://www.cnblogs.com/nlsoft/p/6072064.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!