求一正则对指定文件夹中文件改名排序(批量改名)
问题:现在有一文件夹里有以下文件:
09 - Spell.mp3
14 - Take Your Time.mp3
06 - Bittersweet.mp3
12 - Lullabye For A Stormy Night.mp3
04 - Bubbly.mp3
09 - One Last Time.mp3
01 - We Are One.mp3
05 - Wish You Well.mp3
06 - Top Of The World.mp3
12 - Chanson de Toile.mp3
23 - A Little Love.mp3
11 - Sabra Girl.mp3
12 - Molde Canticle.mp3
10 - Forgotten Sorrow.mp3
07 - Right Now & Right Here.mp3
04 - End Of May.mp3
06 - Found By You (Acoustic).mp3
10 - I'm in Here.mp3
05 - Lose You.mp3
01 - You Are My Angel (Sub Theme Song In Forensic Heroes 2).mp3
07 - Fairy Tale.mp3
01 - Lonely In Paris.mp3
03 - Good Is Good.mp3
04 - There Were Roses.mp3
10 - Again.mp3
06 - Love Has It All.mp3
06 - Key To My Heart.mp3
02 - Eet.mp3
01 - Grown-Up Christmas List.mp3
02 - 原谅.mp3
09 - Yellow.mp3
08 - 那些花儿.mp3
05 - 亲爱的还幸福吗.mp3
03 - 風の記憶.mp3
10 - 慢慢来比较快.mp3
04 - 花园.mp3
11 - 我懂了.mp3
02 - 相思引.mp3
02 - 春の风.mp3
07 - 我真的受伤了.mp3
01 - 错过.mp3
05 - ???? ????.mp3
03 - 怎么说呢_.mp3
07 - 夏天的风.mp3
01 - 岛歌.mp3
01 - 日光倾城.mp3
想将每个文件的序号(如上很乱)重新排列,按01-99模式,以如上的引用的顺序改名
知道需要正则,没法写,,,类似于mp3排序,但又不完全是
最好写全吧,比如来个func,如(原名,改为,模式),模式可有可无,就是说前面序号的位数 "(\d{2})(?= -)" 替换为序号,试一下 "(\d{2})(?= -)" 替换为序号,试一下
kevinch 发表于 2011-2-5 17:41 http://www.autoitx.com/images/common/back.gif
不懂,能详说吗?
试后不行。。。。可能是我不会用哦,我明白了,得到序号了。。。
有点明白,谢谢兄弟 (\d{2})(?= -)
匹配后面是" -"的两位数字,根据你的文件名的特点,得到的就是前面的序号,通过一个循环递增的替换掉这个串应该就可以了,不过是不是杀鸡用牛刀了{:face (197):} 回复 4# kevinch
饿,谢谢,兄弟 谢谢,。。。啦 本帖最后由 lixiaolong 于 2011-2-26 05:06 编辑
回复 1# kn007
本人没什么技术,随便写了个例子.
为了大家方便,写了一个创建mp3文件代码
#include <file.au3>
$File = @ScriptDir & '\a.txt'
$str = FileOpen($File,0)
While 1
$b = FileReadLine($str)
If $b = '' Then ExitLoop
_FileCreate(@ScriptDir & '\mp3\' & $b)
WEnd
a.txt09 - Spell.mp3
14 - Take Your Time.mp3
06 - Bittersweet.mp3
12 - Lullabye For A Stormy Night.mp3
04 - Bubbly.mp3
09 - One Last Time.mp3
01 - We Are One.mp3
05 - Wish You Well.mp3
06 - Top Of The World.mp3
12 - Chanson de Toile.mp3
23 - A Little Love.mp3
11 - Sabra Girl.mp3
12 - Molde Canticle.mp3
10 - Forgotten Sorrow.mp3
07 - Right Now & Right Here.mp3
04 - End Of May.mp3
06 - Found By You (Acoustic).mp3
10 - I'm in Here.mp3
05 - Lose You.mp3
01 - You Are My Angel (Sub Theme Song In Forensic Heroes 2).mp3
07 - Fairy Tale.mp3
01 - Lonely In Paris.mp3
03 - Good Is Good.mp3
04 - There Were Roses.mp3
10 - Again.mp3
06 - Love Has It All.mp3
06 - Key To My Heart.mp3
02 - Eet.mp3
01 - Grown-Up Christmas List.mp3
02 - 原谅.mp3
09 - Yellow.mp3
08 - 那些花儿.mp3
05 - 亲爱的还幸福吗.mp3
03 - 風の記憶.mp3
10 - 慢慢来比较快.mp3
04 - 花园.mp3
11 - 我懂了.mp3
02 - 相思引.mp3
02 - 春の风.mp3
07 - 我真的受伤了.mp3
01 - 错过.mp3
05 - ???? ????.mp3
03 - 怎么说呢_.mp3
07 - 夏天的风.mp3
01 - 岛歌.mp3
01 - 日光倾城.mp3改名例子
#include <file.au3>
_ReName(@ScriptDir & '\mp3')
Func _ReName($SearchDir)
Dim $szDrive, $szDir, $szFName, $szExt
$aFile = _FileListToArray($SearchDir)
If Not @error Then
For $i = 1 To $aFile
$arrPath = _PathSplit($SearchDir & '\' & $aFile[$i], $szDrive, $szDir, $szFName, $szExt)
$Test2 = StringRegExpReplace($szFName & $szExt, '(\d+)(?= -)', '')
If $i < 10 Then
$FileName = '0' & $i & $Test2
Else
$FileName = $i & $Test2
EndIf
RunWait(@ComSpec & ' /c ren "' & $SearchDir & '\' & $aFile[$i] & '" "' & $FileName & '"', '', 0)
Next
EndIf
EndFunc ;==>_ReName 代码学习了......
页:
[1]