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

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

问题描述

我有一批 根据文件顺序创建快捷方式,问题是当涉及到数字时,他在传递数字 100 时会出现以下问题.

01.mp402.mp403.rmvb04.mp405.rmvb06.rmvb07.rmvb08.rmvb09.rmvb10.rmvb100.mp4101.mp4102.mp4103.mp4104.mp4105.mp4106.mp4107.mp4108.mp4109.mp411.rmvb

我在这里搜索并找到了各种方法,但是我使用的脚本适用于有时使用口音&和/或的文件夹和文件!

示例:C:Séries &MoviesRemix!.mkv(巴西和使用 E 的地方和).

不知道有没有什么办法可以在保存到.ini之前或者保存到.ini之后检查内容和组织是否正确.

观察:

  1. 第一次执行 Set 命令时加载文件夹路径.
  2. 输入路径后,他保存在 .ini 文件中并始终加载.
  3. 脚本仅列出目录中的文件,不列出子文件夹以及其中的文件和文件夹.
  4. 脚本需要其他文件才能工作,下载链接如下:https://www.mediafire.com/?zcoybkfo8k4nm1t

我的完整代码:

@Echo 关闭标题按字母顺序创建快捷方式模式 con:lines=3 cols=25颜色 1fCD/D "%~dp0"If Exist "Filescommand.ini" For/f "usebackq delims=" %%x in ("Filescommand.ini") do (set "%%x")If Exist "FilesConfig.ini" For/f "usebackq delims=" %%x in ("FilesConfig.ini") do (set "%%x")如果存在FilesFiles.ini"转到快捷方式如果存在文件command.ini"转到快捷方式如果存在FilesConfig.ini"转到快捷方式对于 (""%1"") 中的 %%F,请设置 "location-of-files=%%~F"对于 %%F in ("%location-of-files%") do IF "%%~F" NEQ """" Set "location-of-files=%location-of-files:"=%" &Set Number=1 & Goto LocationofFiles2:文件位置模式 con:lines=18 cols=78设置location-of-files=r1u4unoiwqa6">nul 2>&1类echo 文件位置设置/p location-of-files="¯ 文件位置:"设置 "location-of-files=%location-of-files:"=%"集数=1IF "%location-of-files%"=="r1u4unoiwqa6" 转到 LocationofFiles:位置文件2模式 con:lines=18 cols=78设置菜单=">nul 2>&1类对于 %%F in ("%location-of-files%") 做 Echo %%~F回声 1(是) 2(否)Set/p Menu="¯ 菜单:"IF "%Menu%"=="1" 转到 IniciarIF "%Menu%"=="2" Goto LocationofFiles转到 LocationofFiles2:Iniciar如果不存在 "%location-of-files%" Cls &启动/Wait FilesError.vbs &转到文件位置:Name-AnimeSerie1设置 "Serie_Anime=">nul 2>&1类echo 名称系列Set/p Serie_Anime="¯ 名称:"IF "%Serie_Anime%"=="" 转到名称-AnimeSerie1:Name-AnimeSerie2设置菜单=">nul 2>&1类对于 ("%Serie_Anime%") 中的 %%F,请执行 Echo %%~F回声 1(是) 2(否)Set/p Menu="¯ 菜单:"IF "%Menu%"=="1" 转到快捷方式IF "%Menu%"=="2" 转到名称-AnimeSerie1转到名称-AnimeSerie2:快捷方式If Exist "FilesConfig.ini" For/f "usebackq delims=" %%x in ("FilesConfig.ini") do (set "%%x")如果不存在 "%location-of-files%" Del/q "C:Users\%username%Desktop\%ep2% - %Serie_Anime%.lnk">nul 2>&1 &开始/Min/Wait FilesDesktopRefresh.exe>nul 2>&1 &转到结束目录/a-d/b "%location-of-files%" >FilesFiles.iniecho r1u4unoiwqa6.ending >>FilesFiles.ini启动 "exclamation01"/Min/Wait "Filesexclamation01.vbs">nul 2>&1设置文件位置 >文件配置文件设置 Serie_Anime >>文件配置文件组数>文件command.ini如果存在 "C:Users\%username%Desktop\%ep2% - %Serie_Anime%.lnk" Del/q "C:Users\%username%Desktop\%ep2% - %Serie_Anime%.lnk">nul 2>&1 &开始/Min/Wait FilesDesktopRefresh.exe>nul 2>&1setlocal EnableDelayedExpansion对于/f "usebackq delims=" %%x in ("Filescommand.ini") do (set "%%x")对于/f "usebackq delims=" %%x in ("FilesConfig.ini") do (set "%%x")设置 "cmd=findstr/R/N "^^" FilesFiles.ini | find/C ":""for/f %%a in ('!cmd!') do set Numbers=%%a设置行=%Number%设置 Atual=1for/f "delims=" %%a in ('type FilesFiles.ini') 做 (对于 (!lines!) 中的 %%b 做 (如果 !Atual!==%%b 设置Ep1=%%a")set/a "Atual = Atual + 1")设置Ep2=%Ep1%"设置查找= *."调用集删除=%%Ep2:!find!=%%调用集 Ep2=%%Ep2:!delete!=%%设置 Ep2=%Ep2:.=%设置 Ep1 >文件command.ini设置 Ep2 >>文件command.ini设置线条 >>文件command.ini集数>>文件command.ini本地端启动 "exclamation02"/Min/Wait "Filesexclamation02.vbs">nul 2>&1对于/f "usebackq delims=" %%x in ("Filescommand.ini") do (set "%%x")对于/f "usebackq delims=" %%x in ("FilesConfig.ini") do (set "%%x")如果%Ep2%"==r1u4unoiwqa6"转到结束开始/Min/Wait FilesShortcut.exe/F:"C:Users\%username%Desktop\%ep2% - %Serie_Anime%.lnk"/A:C/t:"%location-of-files%\%Ep1%"/D:"Episode %Serie_Anime%">nul 2>&1如果不存在 "C:Users\%username%Desktop[快捷方式].lnk" Echo %Serie_Anime%>Filesshortcut.ini &Start/Min/Wait Filesshortcut.vbs>nul 2>&1Set/A Number = %lines% + 1::::::::::::::::::::::::::::::::::::::::::::设置文件位置 >文件配置文件设置 Serie_Anime >>文件配置文件::::::::::::::::::::::::::::::::::::::::::::设置 Ep1 >文件command.ini设置 Ep2 >>文件command.ini集数>>文件command.ini::::::::::::::::::::::::::::::::::::::::::::出口:结尾如果不存在 "%location-of-files%" Start/Wait FilesPDoM.vbs>nul 2>&1如果存在 "%location-of-files%" Start/Wait Filesending.vbs>nul 2>&1如果存在 "%location-of-files%" 启动 "Anime" "%location-of-files%">nul 2>&1Del/q "FilesFiles.ini">nul 2>&1Del/q "Filesshortcut.ini">nul 2>&1Del/q "Filescommand.ini">nul 2>&1Del/q "FilesConfig.ini">nul 2>&1设置location-of-files=">nul 2>&1设置 "Serie_Anime=">nul 2>&1设置 "lines=">nul 2>&1设置 "Ep1=">nul 2>&1设置 "Ep2=">nul 2>&1转到文件位置

需要使用 DIR 的部分:

:快捷键If Exist "FilesConfig.ini" For/f "usebackq delims=" %%x in ("FilesConfig.ini") do (set "%%x")如果不存在 "%location-of-files%" Del/q "C:Users\%username%Desktop\%ep2% - %Serie_Anime%.lnk">nul 2>&1 &开始/Min/Wait FilesDesktopRefresh.exe>nul 2>&1 &转到结束目录/a-d/b "%location-of-files%" >FilesFiles.iniecho r1u4unoiwqa6.ending >>FilesFiles.ini启动 "exclamation01"/Min/Wait "Filesexclamation01.vbs">nul 2>&1设置文件位置 >文件配置文件设置 Serie_Anime >>文件配置文件组数>文件command.ini如果存在 "C:Users\%username%Desktop\%ep2% - %Serie_Anime%.lnk" Del/q "C:Users\%username%Desktop\%ep2% - %Serie_Anime%.lnk">nul 2>&1 &开始/Min/Wait FilesDesktopRefresh.exe>nul 2>&1setlocal EnableDelayedExpansion对于/f "usebackq delims=" %%x in ("Filescommand.ini") do (set "%%x")对于/f "usebackq delims=" %%x in ("FilesConfig.ini") do (set "%%x")设置 "cmd=findstr/R/N "^^" FilesFiles.ini | find/C ":""for/f %%a in ('!cmd!') do set Numbers=%%a设置行=%Number%设置 Atual=1for/f "delims=" %%a in ('type FilesFiles.ini') 做 (对于 (!lines!) 中的 %%b 做 (如果 !Atual!==%%b 设置Ep1=%%a")set/a "Atual = Atual + 1")设置Ep2=%Ep1%"设置查找= *."调用集删除=%%Ep2:!find!=%%调用集 Ep2=%%Ep2:!delete!=%%设置 Ep2=%Ep2:.=%设置 Ep1 >文件command.ini设置 Ep2 >>文件command.ini设置线条 >>文件command.ini集数>>文件command.ini本地端

<块引用>

提前致谢.

解决方案

Set Arg = WScript.Argumentsset WshShell = createObject("Wscript.Shell")设置 Inp = WScript.Stdin设置输出 = Wscript.StdoutSet rs = CreateObject("ADODB.Recordset")如果 LCase(Arg(1)) = "n" 那么与 rs.Fields.Append "SortKey", 4.Fields.Append "Txt", 201, 5000.打开做直到 Inp.AtEndOfStreamLne = Inp.readlineSortKey = Mid(Lne, LCase(Arg(3)), LCase(Arg(4)) - LCase(Arg(3)))如果 IsNumeric(Sortkey) = False 那么设置 RE = 新正则表达式re.Pattern = "[^0-9.,]"re.global = 真re.ignorecase = trueSortkey = re.replace(Sortkey, "")万一如果 IsNumeric(Sortkey) = False 那么排序键 = 0ElseIf Sortkey = "" 那么排序键 = 0ElseIf IsNull(Sortkey) = true 那么排序键 = 0万一.添新.Fields("SortKey").value = CSng(SortKey).Fields("Txt").value = Lne.更新环形如果 LCase(Arg(2)) = "a" 那么 SortColumn = "SortKey ASC"如果 LCase(Arg(2)) = "d" 然后 SortColumn = "SortKey DESC".Sort = SortColumn做而不是 .EOFOutp.writeline .Fields("Txt").Value.MoveNext环形结束于ElseIf LCase(Arg(1)) = "d" 然后与 rs.Fields.Append "SortKey", 4.Fields.Append "Txt", 201, 5000.打开做直到 Inp.AtEndOfStreamLne = Inp.readlineSortKey = Mid(Lne, LCase(Arg(3)), LCase(Arg(4)) - LCase(Arg(3)))如果 IsDate(Sortkey) = False 那么设置 RE = 新正则表达式re.Pattern = "[^0-9\-:]"re.global = 真re.ignorecase = trueSortkey = re.replace(Sortkey, "")万一如果 IsDate(Sortkey) = False 那么排序键 = 0ElseIf Sortkey = "" 那么排序键 = 0ElseIf IsNull(Sortkey) = true 那么排序键 = 0万一.添新.Fields("SortKey").value = CDate(SortKey).Fields("Txt").value = Lne.更新环形如果 LCase(Arg(2)) = "a" 那么 SortColumn = "SortKey ASC"如果 LCase(Arg(2)) = "d" 然后 SortColumn = "SortKey DESC".Sort = SortColumn做而不是 .EOFOutp.writeline .Fields("Txt").Value.MoveNext环形结束于ElseIf LCase(Arg(1)) = "t" then与 rs.Fields.Append "SortKey", 201, 260.Fields.Append "Txt", 201, 5000.打开做直到 Inp.AtEndOfStreamLne = Inp.readlineSortKey = Mid(Lne, LCase(Arg(3)), LCase(Arg(4)) - LCase(Arg(3))).添新.Fields("SortKey").value = SortKey.Fields("Txt").value = Lne.更新环形如果 LCase(Arg(2)) = "a" 那么 SortColumn = "SortKey ASC"如果 LCase(Arg(2)) = "d" 然后 SortColumn = "SortKey DESC".Sort = SortColumn做而不是 .EOFOutp.writeline .Fields("Txt").Value.MoveNext环形结束于ElseIf LCase(Arg(1)) = "tt" then与 rs.Fields.Append "SortKey", 201, 260.Fields.Append "Txt", 201, 5000.打开做直到 Inp.AtEndOfStreamLne = Inp.readlineSortKey = Trim(Mid(Lne, LCase(Arg(3)), LCase(Arg(4)) - LCase(Arg(3)))).添新.Fields("SortKey").value = SortKey.Fields("Txt").value = Lne.更新环形如果 LCase(Arg(2)) = "a" 那么 SortColumn = "SortKey ASC"如果 LCase(Arg(2)) = "d" 然后 SortColumn = "SortKey DESC".Sort = SortColumn做而不是 .EOFOutp.writeline .Fields("Txt").Value.MoveNext环形结束于万一

使用

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

选项

n - 从指定的列中提取一个数字.寻找第一个数字.d - 从指定的列中提取时间或日期.寻找第一次约会.t - 从指定的列中提取包含空格的文本字符串.tt - 从指定的列中提取丢弃前导和尾随空格的文本字符串.a - 排序升序d - 排序降序startcolumn - 起始列,第一个字符是第 1 列endcolumn - 结束列

这就是命令行语法的含义

下表描述了用于指示命令行语法的符号.

符号说明

不带括号或大括号的文本您必须输入的项目如图所示<尖括号内的文字>必须为其提供值的占位符[方括号内的文字]可选项目{大括号内的文字}所需物品的集合;选一个竖线 (|)互斥项目的分隔符;选一个省略号 (…)可重复的项目

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 & MoviesRemix!.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 "Filescommand.ini" For /f "usebackq delims=" %%x in ("Filescommand.ini") do (set "%%x")
If Exist "FilesConfig.ini" For /f "usebackq delims=" %%x in ("FilesConfig.ini") do (set "%%x")
If Exist "FilesFiles.ini" Goto shortcuts
If Exist "Filescommand.ini" Goto shortcuts
If Exist "FilesConfig.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 FilesError.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 "FilesConfig.ini" For /f "usebackq delims=" %%x in ("FilesConfig.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 FilesDesktopRefresh.exe>nul 2>&1 & Goto end
Dir /a-d /b "%location-of-files%" >FilesFiles.ini
Echo r1u4unoiwqa6.ending >>FilesFiles.ini

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

Set location-of-files > FilesConfig.ini
Set Serie_Anime >> FilesConfig.ini
Set Number > Filescommand.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 FilesDesktopRefresh.exe>nul 2>&1

setlocal EnableDelayedExpansion

For /f "usebackq delims=" %%x in ("Filescommand.ini") do (set "%%x")
For /f "usebackq delims=" %%x in ("FilesConfig.ini") do (set "%%x")

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

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

set lines=%Number%
set Atual=1
for /f "delims=" %%a in ('type FilesFiles.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 > Filescommand.ini
Set Ep2 >> Filescommand.ini
Set lines >> Filescommand.ini
Set Number >> Filescommand.ini

endlocal

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

For /f "usebackq delims=" %%x in ("Filescommand.ini") do (set "%%x")
For /f "usebackq delims=" %%x in ("FilesConfig.ini") do (set "%%x")

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

Start /Min /Wait FilesShortcut.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%>Filesshortcut.ini & Start /Min /Wait Filesshortcut.vbs>nul 2>&1
Set /A Number = %lines% + 1
:::::::::::::::::::::::::::::::::::::::::::::
Set location-of-files > FilesConfig.ini
Set Serie_Anime >> FilesConfig.ini
:::::::::::::::::::::::::::::::::::::::::::::
Set Ep1 > Filescommand.ini
Set Ep2 >> Filescommand.ini
Set Number >> Filescommand.ini
:::::::::::::::::::::::::::::::::::::::::::::
Exit

:end
If Not Exist "%location-of-files%" Start /Wait FilesPDoM.vbs>nul 2>&1
If Exist "%location-of-files%" Start /Wait Filesending.vbs>nul 2>&1
If Exist "%location-of-files%" Start "Anime" "%location-of-files%">nul 2>&1
Del /q "FilesFiles.ini">nul 2>&1
Del /q "Filesshortcut.ini">nul 2>&1
Del /q "Filescommand.ini">nul 2>&1
Del /q "FilesConfig.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 "FilesConfig.ini" For /f "usebackq delims=" %%x in ("FilesConfig.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 FilesDesktopRefresh.exe>nul 2>&1 & Goto end
Dir /a-d /b "%location-of-files%" >FilesFiles.ini
Echo r1u4unoiwqa6.ending >>FilesFiles.ini

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

Set location-of-files > FilesConfig.ini
Set Serie_Anime >> FilesConfig.ini
Set Number > Filescommand.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 FilesDesktopRefresh.exe>nul 2>&1

setlocal EnableDelayedExpansion

For /f "usebackq delims=" %%x in ("Filescommand.ini") do (set "%%x")
For /f "usebackq delims=" %%x in ("FilesConfig.ini") do (set "%%x")

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

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

set lines=%Number%
set Atual=1
for /f "delims=" %%a in ('type FilesFiles.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 > Filescommand.ini
Set Ep2 >> Filescommand.ini
Set lines >> Filescommand.ini
Set Number >> Filescommand.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天全站免登陆