按数字顺序排序文件 [英] Sorting files by numerical order

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

问题描述

我有一个批次create基于文件的顺序快捷方式,问题是,当涉及到数字,他路过$数100当p $ psents以下问题。

  01.mp4
02.mp4
03.rmvb
04.mp4
05.rmvb
06.rmvb
07.rmvb
08.rmvb
09.rmvb
10.rmvb
100.mp4
101.mp4
102.mp4
103.mp4
104.mp4
105.mp4
106.mp4
107.mp4
108.mp4
109.mp4
11.rmvb

我搜索这里找到各种方法但是剧本我用文件夹和文件的作品,有时使用口音 &安培;!和/或

 例如:C:\\系列&安培;电影\\不怕!的.mkv(巴西和用E的地方,)。

我不知道是否有任何方法来检查的内容和组织也可以得到妥善保存它的.ini或保存在相同的.ini前后。

的意见:


  1. 文件夹路径是第一次加载设置命令。

  2. 进入他保存在.ini文件,并总是加载路径之后。

  3. 脚本只列出目录中的文件并没有在其中列出子文件夹和文件和文件夹。

  4. 的脚本需要其他文件工作的下载链接是如下:
    https://www.mediafire.com/?zcoybkfo8k4nm1t

我的全部code:

  @回响标题创建按字母顺序排列的快捷键
模式CON:行= 3 COLS = 25
颜色1FCD / D%〜DP0如果存在文件\\ command.ini对于%%倍In(文件\\ command.ini)就(将%% X)/ F=有usebackq delims
如果存在文件\\的Config.iniFOR / F有usebackq delims =%%倍In(文件\\的Config.ini),做(集%% X)
如果存在文件\\ Files.ini转到快捷键
如果存在文件\\ command.ini转到快捷键
如果存在文件\\的Config.ini转到快捷键为%% f由于(%1)做集位置的档案= %%〜F
为%% f由于(%位置的档案%)做,如果%%〜FNEQ设置位置的档案=%位置的-文件:=%&放大器;集数= 1&安培;转到LocationofFiles2:LocationofFiles
模式CON:行= 18 COLS = 78
集位置的档案= r1u4unoiwqa6> NUL 2 - ;&放大器; 1
CLS
文件的回声定位
设置/对位置的档案=¯文件的位置:
集位置的档案=%位置的-文件:=%
集数= 1
IF%位置的档案%==r1u4unoiwqa6转到LocationofFiles
:LocationofFiles2
模式CON:行= 18 COLS = 78
设置菜单=> NUL 2 - ;&放大器; 1
CLS
为%% f由于(%位置的档案%)做回声%%〜F
回音1(是)2(否)
设定/ p菜单=¯菜单:
IF%菜单%==1转到Iniciar
IF%菜单%==2转到LocationofFiles
转到LocationofFiles2:Iniciar
如果不存在%位置的档案%Cls的&安培;启动/等待文件\\ Error.vbs&安培;转到LocationofFiles:名称 - AnimeSerie1
设置Serie_Anime => NUL 2 - ;&放大器; 1
CLS
回声名称意甲
设置/ p Serie_Anime =¯名称:
IF%Serie_Anime%==转到名称 - AnimeSerie1
:名称 - AnimeSerie2
设置菜单=> NUL 2 - ;&放大器; 1
CLS
为%% f由于(%Serie_Anime%)做回声%%〜F
回音1(是)2(否)
设定/ p菜单=¯菜单:
IF%菜单%==1转到快捷键
IF%菜单%==2转到名称 - AnimeSerie1
转到名称 - AnimeSerie2:快捷键
如果存在文件\\的Config.iniFOR / F有usebackq delims =%%倍In(文件\\的Config.ini),做(集%% X)
如果不存在%位置的档案%DEL / QC:\\用户\\%用户名%\\桌面\\%EP2% - %Serie_Anime%的.lnk> NUL 2 - ;&放大器; 1安培;启动/最小/等待文件\\ Deskto prefresh.exe> NUL 2 - ;&放大器; 1安培;转到结束
DIR / A-D / B%位置的档案%>文件\\ Files.ini
回声r1u4unoiwqa6.ending>>文件\\ Files.ini启动exclamation01/最小/等待文件\\ exclamation01.vbs> NUL 2 - ;&放大器; 1设置位置的-文件>文件\\的Config.ini
设置Serie_Anime>>文件\\的Config.ini
定数>文件\\ command.ini如果存在C:\\用户\\%USERNAME%\\桌面\\%EP2% - %Serie_Anime%的.lnkDEL / QC:\\用户\\%USERNAME%\\桌面\\%EP2% - %Serie_Anime%的.lnk&GT ; NUL 2 - ;&放大器; 1和;启动/最小/等待文件\\ Deskto prefresh.exe> NUL 2 - ;&放大器; 1SETLOCAL EnableDelayedExpansionFOR / F有usebackq delims =%%倍In(文件\\ command.ini)就(将%% X)
FOR / F有usebackq delims =%%倍In(文件\\的Config.ini)就(将%% X)设置CMD = FINDSTR / R / N^^文件\\ Files.ini |找到/ C:FOR / F %%一个在('!CMD!')做一组数字= %%一套系=%人数%
设置Atual = 1
FOR / Fdelims =%%一中(类型的文件\\ Files.ini')做(
    在%% B(!行!)做(
        如果!Atual!== %% b将EP1 = %%一个
    )
    集/ AAtual = At​​ual + 1
)设置EP2 =%EP1%
设置中找到= *。
呼叫建立删除= %% EP2:!找到= %%
呼叫建立EP2 = %% EP2:!删除= %%
设置EP2 =%EP2:=%设置EP1>文件\\ command.ini
设置EP2>>文件\\ command.ini
套系GT&;>文件\\ command.ini
定数>>文件\\ command.iniENDLOCAL启动exclamation02/最小/等待文件\\ exclamation02.vbs> NUL 2 - ;&放大器; 1FOR / F有usebackq delims =%%倍In(文件\\ command.ini)就(将%% X)
FOR / F有usebackq delims =%%倍In(文件\\的Config.ini)就(将%% X)IF%EP2%==r1u4unoiwqa6转到结束启动/最小/等待文件\\ Shortcut.exe / F:C:\\用户\\%USERNAME%\\桌面\\%EP2% - %Serie_Anime%的.lnk/ A:C / T:%位置的档案% \\%EP1%/ D:情节%Serie_Anime%> NUL 2 - ;&放大器; 1
如果不存在C:\\用户\\%USERNAME%\\桌面\\ [快捷键] .LNK回声%Serie_Anime%GT;文件\\ shortcut.ini&安培;启动/最小/等待文件\\ shortcut.vbs> NUL 2 - ;&放大器; 1
设置/ A数=%线%+ 1
:::::::::::::::::::::::::::::::::::::::::::::
设置位置的-文件>文件\\的Config.ini
设置Serie_Anime>>文件\\的Config.ini
:::::::::::::::::::::::::::::::::::::::::::::
设置EP1>文件\\ command.ini
设置EP2>>文件\\ command.ini
定数>>文件\\ command.ini
:::::::::::::::::::::::::::::::::::::::::::::
出口:结束
如果不存在%位置的档案%开始/等待文件\\ PDoM.vbs> NUL 2 - ;&放大器; 1
如果存在%位置的档案%开始/等待文件\\ ending.vbs> NUL 2 - ;&放大器; 1
如果存在%位置的档案%开始动漫,%位置的档案%> NUL 2 - ;&放大器; 1
DEL / Q文件\\ Files.ini> NUL 2 - ;&放大器; 1
DEL / Q文件\\ shortcut.ini> NUL 2 - ;&放大器; 1
DEL / Q文件\\ command.ini> NUL 2 - ;&放大器; 1
DEL / Q文件\\的Config.ini> NUL 2 - ;&放大器; 1
将位置的档案=> NUL 2 - ;&放大器; 1
设置Serie_Anime => NUL 2 - ;&放大器; 1
设置行=> NUL 2 - ;&放大器; 1
设置EP1 => NUL 2 - ;&放大器; 1
设置EP2 => NUL 2 - ;&放大器; 1
转到LocationofFiles

部分,你需要使用DIR:

 :快捷键
如果存在文件\\的Config.iniFOR / F有usebackq delims =%%倍In(文件\\的Config.ini),做(集%% X)
如果不存在%位置的档案%DEL / QC:\\用户\\%用户名%\\桌面\\%EP2% - %Serie_Anime%的.lnk> NUL 2 - ;&放大器; 1安培;启动/最小/等待文件\\ Deskto prefresh.exe> NUL 2 - ;&放大器; 1安培;转到结束
DIR / A-D / B%位置的档案%>文件\\ Files.ini
回声r1u4unoiwqa6.ending>>文件\\ Files.ini启动exclamation01/最小/等待文件\\ exclamation01.vbs> NUL 2 - ;&放大器; 1设置位置的-文件>文件\\的Config.ini
设置Serie_Anime>>文件\\的Config.ini
定数>文件\\ command.ini如果存在C:\\用户\\%USERNAME%\\桌面\\%EP2% - %Serie_Anime%的.lnkDEL / QC:\\用户\\%USERNAME%\\桌面\\%EP2% - %Serie_Anime%的.lnk&GT ; NUL 2 - ;&放大器; 1和;启动/最小/等待文件\\ Deskto prefresh.exe> NUL 2 - ;&放大器; 1SETLOCAL EnableDelayedExpansionFOR / F有usebackq delims =%%倍In(文件\\ command.ini)就(将%% X)
FOR / F有usebackq delims =%%倍In(文件\\的Config.ini)就(将%% X)设置CMD = FINDSTR / R / N^^文件\\ Files.ini |找到/ C:FOR / F %%一个在('!CMD!')做一组数字= %%一套系=%人数%
设置Atual = 1
FOR / Fdelims =%%一中(类型的文件\\ Files.ini')做(
    在%% B(!行!)做(
        如果!Atual!== %% b将EP1 = %%一个
    )
    集/ AAtual = At​​ual + 1
)设置EP2 =%EP1%
设置中找到= *。
呼叫建立删除= %% EP2:!找到= %%
呼叫建立EP2 = %% EP2:!删除= %%
设置EP2 =%EP2:=%设置EP1>文件\\ command.ini
设置EP2>>文件\\ command.ini
套系GT&;>文件\\ command.ini
定数>>文件\\ command.iniENDLOCAL


  

先谢谢了。



解决方案

 设置精氨酸= WScript.Arguments
设置的WshShell =的CreateObject(Wscript.Shell)
设置INP = WScript.Stdin
设置OUTP = Wscript.Stdout
    集RS =的CreateObject(ADODB.Recordset)
    如果LCASE(精氨酸(1))=N则
    随着RS
        .Fields.AppendSORTKEY,4
        .Fields.AppendTXT,201,5000
        。打开
        做,直到Inp.AtEndOfStream
            LNE = Inp.readline
            SORTKEY =中(LNE,LCASE(精氨酸(3)),LCASE(精氨酸(4)) - LCASE(精氨酸(3)))
            如果IsNumeric函数(SORTKEY)= false,那么
                设定RE =新的正则表达式
                re.Pattern =[^ 0-9 \\,]
                re.global =真
                re.ignorecase =真
                SORTKEY = re.replace(SORTKEY,)
            万一
            如果IsNumeric函数(SORTKEY)= false,那么
                SORTKEY = 0
            elseif的SORTKEY =然后
                SORTKEY = 0
            elseif的ISNULL(SORTKEY)= true,那么
                SORTKEY = 0
            万一
            。添新
            点域(SORTKEY)。值= CSng函数(SORTKEY)
            点域(TXT)。值= LNE
            .UpDate
        循环
        如果LCASE(精氨酸(2))=A,然后SortColumn =SORTKEY ASC
        如果LCASE(精氨酸(2))=D,然后SortColumn =SORTKEY DESC
        的.sort = SortColumn
        这样做虽然没有.EOF
            Outp.writeline点域(TXT)。价值
            .MoveNext
        循环
    结束与    elseif的LCASE(精氨酸(1))=D,然后
    随着RS
        .Fields.AppendSORTKEY,4
        .Fields.AppendTXT,201,5000
        。打开
        做,直到Inp.AtEndOfStream
            LNE = Inp.readline
            SORTKEY =中(LNE,LCASE(精氨酸(3)),LCASE(精氨酸(4)) - LCASE(精氨酸(3)))
            如果则IsDate(SORTKEY)= false,那么
                设定RE =新的正则表达式
                re.Pattern =[^ 0-9 \\\\\\ - :]
                re.global =真
                re.ignorecase =真
                SORTKEY = re.replace(SORTKEY,)
            万一
            如果则IsDate(SORTKEY)= false,那么
                SORTKEY = 0
            elseif的SORTKEY =然后
                SORTKEY = 0
            elseif的ISNULL(SORTKEY)= true,那么
                SORTKEY = 0
            万一
            。添新
            点域(SORTKEY)。值= CDATE(SORTKEY)
            点域(TXT)。值= LNE
            .UpDate
        循环
        如果LCASE(精氨酸(2))=A,然后SortColumn =SORTKEY ASC
        如果LCASE(精氨酸(2))=D,然后SortColumn =SORTKEY DESC
        的.sort = SortColumn
        这样做虽然没有.EOF
            Outp.writeline点域(TXT)。价值
            .MoveNext
        循环
    结束与
    elseif的LCASE(精氨酸(1))=T则
    随着RS
        .Fields.AppendSORTKEY,201,260
        .Fields.AppendTXT,201,5000
        。打开
        做,直到Inp.AtEndOfStream
            LNE = Inp.readline
            SORTKEY =中(LNE,LCASE(精氨酸(3)),LCASE(精氨酸(4)) - LCASE(精氨酸(3)))
            。添新
            点域(SORTKEY)。值= SORTKEY
            点域(TXT)。值= LNE
            .UpDate
        循环
        如果LCASE(精氨酸(2))=A,然后SortColumn =SORTKEY ASC
        如果LCASE(精氨酸(2))=D,然后SortColumn =SORTKEY DESC
        的.sort = SortColumn
        这样做虽然没有.EOF
            Outp.writeline点域(TXT)。价值
            .MoveNext
        循环
    结束与
    elseif的LCASE(精氨酸(1))=TT,那么
    随着RS
        .Fields.AppendSORTKEY,201,260
        .Fields.AppendTXT,201,5000
        。打开
        做,直到Inp.AtEndOfStream
            LNE = Inp.readline
            SORTKEY =修剪(MID(LNE,LCASE(精氨酸(3)),LCASE(精氨酸(4)) - LCASE(精氨酸(3))))
            。添新
            点域(SORTKEY)。值= SORTKEY
            点域(TXT)。值= LNE
            .UpDate
        循环
        如果LCASE(精氨酸(2))=A,然后SortColumn =SORTKEY ASC
        如果LCASE(精氨酸(2))=D,然后SortColumn =SORTKEY DESC
        的.sort = SortColumn
        这样做虽然没有.EOF
            Outp.writeline点域(TXT)。价值
            .MoveNext
        循环
    结束与
    万一

要使用

  CSCRIPT // NOLOGO script.vbs排序{N | D | T | TT} {A | D} STARTCOLUMN ENDCOLUMN< input.txt的> output.txt的

选项

  N  - 提取从指定的列的数字。查找第一个号码。
ð - 提取从规定的列的时间或日期。查找第一次约会。
笔 - 提取文本字符串包括指定的列的空间。
TT - 提取文本字符串丢弃开头和结尾,从指定的列的空间。
一个 - 各种acending
ð - 各种decending
STARTCOLUMN - 起始列,第一个字符是第1列
ENDCOLUMN - 结束列

这是命令行synax手段

下表说明了用于表示命令行语法的符号。

符号说明

 文本没有括号或花括号
 你必须键入如显示的项目<尖括号&GT内部文本;
 占位符,你必须提供一个值[方括号内的文字]
 可选项目{文本中括号}
 将所需物品的;选一个竖线(|)
 分隔符互斥项目;选一个省略号(...)
 可重复的项

I have a batch that create shortcut based on the order of files, the problem is that when it comes to numbers he presents the following problem when passing the number 100.

01.mp4
02.mp4
03.rmvb
04.mp4
05.rmvb
06.rmvb
07.rmvb
08.rmvb
09.rmvb
10.rmvb
100.mp4
101.mp4
102.mp4
103.mp4
104.mp4
105.mp4
106.mp4
107.mp4
108.mp4
109.mp4
11.rmvb

I searched here and found various methods however the script I use works with folders and files that sometimes use accents, & and/or !

Example: C:\Séries & Movies\Remix!.mkv (Brazil and use E place of and).

I wonder if there is any way to check the content and organize it can be properly before you save it in .ini or after saving the same in .ini.

Observations:

  1. The folder path is loaded the first time the Set command.
  2. After entering the path he saved in an .ini file and always loaded.
  3. The Script list only files within the directory does not list subfolders and files and folders within it.
  4. The script needs other files to work the download link is below: https://www.mediafire.com/?zcoybkfo8k4nm1t

My Full Code:

@Echo off

Title Create shortcuts in alphabetical order
mode con:lines=3 cols=25
Color 1f

CD /D "%~dp0"

If Exist "Files\command.ini" For /f "usebackq delims=" %%x in ("Files\command.ini") do (set "%%x")
If Exist "Files\Config.ini" For /f "usebackq delims=" %%x in ("Files\Config.ini") do (set "%%x")
If Exist "Files\Files.ini" Goto shortcuts
If Exist "Files\command.ini" Goto shortcuts
If Exist "Files\Config.ini" Goto shortcuts

for %%F in (""%1"") do Set "location-of-files=%%~F"
for %%F in ("%location-of-files%") do IF "%%~F" NEQ """" Set "location-of-files=%location-of-files:"=%" & Set Number=1 & Goto LocationofFiles2

:LocationofFiles
mode con:lines=18 cols=78
Set "location-of-files=r1u4unoiwqa6">nul 2>&1
cls
echo Location of Files
Set /p location-of-files="¯ Location of Files: " 
Set "location-of-files=%location-of-files:"=%"
Set Number=1
IF "%location-of-files%"=="r1u4unoiwqa6" Goto LocationofFiles


:LocationofFiles2
mode con:lines=18 cols=78
Set "Menu=">nul 2>&1
cls
for %%F in ("%location-of-files%") do Echo %%~F
echo 1(Yes) 2(No)
Set/p Menu="¯ Menu: "
IF "%Menu%"=="1" Goto Iniciar
IF "%Menu%"=="2" Goto LocationofFiles
Goto LocationofFiles2

:Iniciar
if not exist "%location-of-files%" Cls & Start /Wait Files\Error.vbs & Goto LocationofFiles

:Name-AnimeSerie1
Set "Serie_Anime=">nul 2>&1
cls
echo Name Serie
Set /p Serie_Anime="¯ Name: " 
IF "%Serie_Anime%"=="" Goto Name-AnimeSerie1


:Name-AnimeSerie2
Set "Menu=">nul 2>&1
cls
for %%F in ("%Serie_Anime%") do Echo %%~F
echo 1(Yes) 2(No)
Set/p Menu="¯ Menu: "
IF "%Menu%"=="1" Goto shortcuts
IF "%Menu%"=="2" Goto Name-AnimeSerie1
Goto Name-AnimeSerie2

:shortcuts
If Exist "Files\Config.ini" For /f "usebackq delims=" %%x in ("Files\Config.ini") do (set "%%x")
If Not Exist "%location-of-files%" Del /q "C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk">nul 2>&1 & Start /Min /Wait Files\DesktopRefresh.exe>nul 2>&1 & Goto end
Dir /a-d /b "%location-of-files%" >Files\Files.ini
Echo r1u4unoiwqa6.ending >>Files\Files.ini

Start "exclamation01" /Min /Wait "Files\exclamation01.vbs">nul 2>&1

Set location-of-files > Files\Config.ini
Set Serie_Anime >> Files\Config.ini
Set Number > Files\command.ini

If Exist "C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk" Del /q "C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk">nul 2>&1 & Start /Min /Wait Files\DesktopRefresh.exe>nul 2>&1

setlocal EnableDelayedExpansion

For /f "usebackq delims=" %%x in ("Files\command.ini") do (set "%%x")
For /f "usebackq delims=" %%x in ("Files\Config.ini") do (set "%%x")

set "cmd=findstr /R /N "^^" Files\Files.ini | find /C ":""

for /f %%a in ('!cmd!') do set Numbers=%%a

set lines=%Number%
set Atual=1
for /f "delims=" %%a in ('type Files\Files.ini') do (
    for %%b in (!lines!) do (
        if !Atual!==%%b Set "Ep1=%%a"
    )
    set /a "Atual = Atual + 1"
)

Set "Ep2=%Ep1%"
set "find=*."
call set delete=%%Ep2:!find!=%%
call set Ep2=%%Ep2:!delete!=%%
Set Ep2=%Ep2:.=%

Set Ep1 > Files\command.ini
Set Ep2 >> Files\command.ini
Set lines >> Files\command.ini
Set Number >> Files\command.ini

endlocal

Start "exclamation02" /Min /Wait "Files\exclamation02.vbs">nul 2>&1

For /f "usebackq delims=" %%x in ("Files\command.ini") do (set "%%x")
For /f "usebackq delims=" %%x in ("Files\Config.ini") do (set "%%x")

IF "%Ep2%"=="r1u4unoiwqa6" Goto end

Start /Min /Wait Files\Shortcut.exe /F:"C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk" /A:C /t:"%location-of-files%\%Ep1%" /D:"Episode %Serie_Anime%">nul 2>&1
If Not Exist "C:\Users\%username%\Desktop\[ shortcuts ].lnk" Echo %Serie_Anime%>Files\shortcut.ini & Start /Min /Wait Files\shortcut.vbs>nul 2>&1
Set /A Number = %lines% + 1
:::::::::::::::::::::::::::::::::::::::::::::
Set location-of-files > Files\Config.ini
Set Serie_Anime >> Files\Config.ini
:::::::::::::::::::::::::::::::::::::::::::::
Set Ep1 > Files\command.ini
Set Ep2 >> Files\command.ini
Set Number >> Files\command.ini
:::::::::::::::::::::::::::::::::::::::::::::
Exit

:end
If Not Exist "%location-of-files%" Start /Wait Files\PDoM.vbs>nul 2>&1
If Exist "%location-of-files%" Start /Wait Files\ending.vbs>nul 2>&1
If Exist "%location-of-files%" Start "Anime" "%location-of-files%">nul 2>&1
Del /q "Files\Files.ini">nul 2>&1
Del /q "Files\shortcut.ini">nul 2>&1
Del /q "Files\command.ini">nul 2>&1
Del /q "Files\Config.ini">nul 2>&1
Set "location-of-files=">nul 2>&1
Set "Serie_Anime=">nul 2>&1
Set "lines=">nul 2>&1
Set "Ep1=">nul 2>&1
Set "Ep2=">nul 2>&1
Goto LocationofFiles

Part where you need to use the DIR:

:shortcuts
If Exist "Files\Config.ini" For /f "usebackq delims=" %%x in ("Files\Config.ini") do (set "%%x")
If Not Exist "%location-of-files%" Del /q "C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk">nul 2>&1 & Start /Min /Wait Files\DesktopRefresh.exe>nul 2>&1 & Goto end
Dir /a-d /b "%location-of-files%" >Files\Files.ini
Echo r1u4unoiwqa6.ending >>Files\Files.ini

Start "exclamation01" /Min /Wait "Files\exclamation01.vbs">nul 2>&1

Set location-of-files > Files\Config.ini
Set Serie_Anime >> Files\Config.ini
Set Number > Files\command.ini

If Exist "C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk" Del /q "C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk">nul 2>&1 & Start /Min /Wait Files\DesktopRefresh.exe>nul 2>&1

setlocal EnableDelayedExpansion

For /f "usebackq delims=" %%x in ("Files\command.ini") do (set "%%x")
For /f "usebackq delims=" %%x in ("Files\Config.ini") do (set "%%x")

set "cmd=findstr /R /N "^^" Files\Files.ini | find /C ":""

for /f %%a in ('!cmd!') do set Numbers=%%a

set lines=%Number%
set Atual=1
for /f "delims=" %%a in ('type Files\Files.ini') do (
    for %%b in (!lines!) do (
        if !Atual!==%%b Set "Ep1=%%a"
    )
    set /a "Atual = Atual + 1"
)

Set "Ep2=%Ep1%"
set "find=*."
call set delete=%%Ep2:!find!=%%
call set Ep2=%%Ep2:!delete!=%%
Set Ep2=%Ep2:.=%

Set Ep1 > Files\command.ini
Set Ep2 >> Files\command.ini
Set lines >> Files\command.ini
Set Number >> Files\command.ini

endlocal

Thanks in advance.

解决方案

Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
    Set rs = CreateObject("ADODB.Recordset")
    If LCase(Arg(1)) = "n" then
    With rs
        .Fields.Append "SortKey", 4 
        .Fields.Append "Txt", 201, 5000 
        .Open
        Do Until Inp.AtEndOfStream
            Lne = Inp.readline
            SortKey = Mid(Lne, LCase(Arg(3)), LCase(Arg(4)) - LCase(Arg(3)))
            If IsNumeric(Sortkey) = False then
                Set RE = new Regexp
                re.Pattern = "[^0-9\.,]"
                re.global = true
                re.ignorecase = true
                Sortkey = re.replace(Sortkey, "")
            End If
            If IsNumeric(Sortkey) = False then
                Sortkey = 0
            ElseIf Sortkey = "" then
                Sortkey = 0
            ElseIf IsNull(Sortkey) = true then
                Sortkey = 0
            End If
            .AddNew
            .Fields("SortKey").value = CSng(SortKey)
            .Fields("Txt").value = Lne
            .UpDate
        Loop
        If LCase(Arg(2)) = "a" then SortColumn = "SortKey ASC"
        If LCase(Arg(2)) = "d" then SortColumn = "SortKey DESC"
        .Sort = SortColumn
        Do While not .EOF
            Outp.writeline .Fields("Txt").Value
            .MoveNext
        Loop
    End With

    ElseIf LCase(Arg(1)) = "d" then
    With rs
        .Fields.Append "SortKey", 4 
        .Fields.Append "Txt", 201, 5000 
        .Open
        Do Until Inp.AtEndOfStream
            Lne = Inp.readline
            SortKey = Mid(Lne, LCase(Arg(3)), LCase(Arg(4)) - LCase(Arg(3)))
            If IsDate(Sortkey) = False then
                Set RE = new Regexp
                re.Pattern = "[^0-9\\\-:]"
                re.global = true
                re.ignorecase = true
                Sortkey = re.replace(Sortkey, "")
            End If
            If IsDate(Sortkey) = False then
                Sortkey = 0
            ElseIf Sortkey = "" then
                Sortkey = 0
            ElseIf IsNull(Sortkey) = true then
                Sortkey = 0
            End If
            .AddNew
            .Fields("SortKey").value = CDate(SortKey)
            .Fields("Txt").value = Lne
            .UpDate
        Loop
        If LCase(Arg(2)) = "a" then SortColumn = "SortKey ASC"
        If LCase(Arg(2)) = "d" then SortColumn = "SortKey DESC"
        .Sort = SortColumn
        Do While not .EOF
            Outp.writeline .Fields("Txt").Value
            .MoveNext
        Loop
    End With


    ElseIf LCase(Arg(1)) = "t" then
    With rs
        .Fields.Append "SortKey", 201, 260 
        .Fields.Append "Txt", 201, 5000 
        .Open
        Do Until Inp.AtEndOfStream
            Lne = Inp.readline
            SortKey = Mid(Lne, LCase(Arg(3)), LCase(Arg(4)) - LCase(Arg(3)))
            .AddNew
            .Fields("SortKey").value = SortKey
            .Fields("Txt").value = Lne
            .UpDate
        Loop
        If LCase(Arg(2)) = "a" then SortColumn = "SortKey ASC"
        If LCase(Arg(2)) = "d" then SortColumn = "SortKey DESC"
        .Sort = SortColumn
        Do While not .EOF
            Outp.writeline .Fields("Txt").Value
            .MoveNext
        Loop
    End With
    ElseIf LCase(Arg(1)) = "tt" then
    With rs
        .Fields.Append "SortKey", 201, 260 
        .Fields.Append "Txt", 201, 5000 
        .Open
        Do Until Inp.AtEndOfStream
            Lne = Inp.readline
            SortKey = Trim(Mid(Lne, LCase(Arg(3)), LCase(Arg(4)) - LCase(Arg(3))))
            .AddNew
            .Fields("SortKey").value = SortKey
            .Fields("Txt").value = Lne
            .UpDate
        Loop
        If LCase(Arg(2)) = "a" then SortColumn = "SortKey ASC"
        If LCase(Arg(2)) = "d" then SortColumn = "SortKey DESC"
        .Sort = SortColumn
        Do While not .EOF
            Outp.writeline .Fields("Txt").Value
            .MoveNext
        Loop
    End With
    End If

To use

cscript //nologo script.vbs sort {n|d|t|tt} {a|d} startcolumn  endcolumn < input.txt > output.txt

Options

n - extracts a number from the columns specified. Looks for the first number.
d - extracts a time or date from the columns specified. Looks for the first date.
t - extracts a text string including spaces from the columns specified.
tt - extracts a text string discarding leading and trailing spaces from the columns specified.
a - sorts acending
d - sorts decending
startcolumn - the starting column, the first character is column 1
endcolumn - the ending column

This is what command line synax means

The following table describes the notation used to indicate command-line syntax.

Notation Description

Text without brackets or braces
 Items you must type as shown

<Text inside angle brackets>
 Placeholder for which you must supply a value

[Text inside square brackets]
 Optional items

{Text inside braces}
 Set of required items; choose one

Vertical bar (|)
 Separator for mutually exclusive items; choose one

Ellipsis (…)
 Items that can be repeated

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

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