比如文件夹里有 001.a.mp3 002.b.mp3 003.c.mp3。然后修改文本文件中的内容为 002.b.mp3 003.c.mp3 001.a.mp3,然后继续执行会将文件重命名为 001.b.mp3 002.c.mp3 003.a.mp3。
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
FileList := "" ; Initialize to be blank.
Loop, .\files\*.*
FileList .= A_LoopFileName "`n"
;Sort, FileList, R ; The R option sorts in reverse order. See Sort for other options.
FileDelete, .\test.txt
FileAppend, %FileList%, .\test.txt
MsgBox,,, 继续
FileRead, newFileList, test.txt
newFileArray := StrSplit(newFileList, "`n")
FileDelete, .\test2.txt
For key, oldFileName in newFileArray{
newFileName := Format("{:03}", A_Index) . "." . SubStr(oldFileName, 5)
oldFileName := ".\files\" . oldFileName
;newFileName := ".\files\" . newFileName
FileAppend, %oldFileName%`n, .\test2.txt
FileAppend, %newFileName%`n`n, .\test2.txt
;FileMove, %oldFileName%, %newFileName%
Run, %ComSpec% /c rename "%oldFileName%" "%newFileName%"
}
MsgBox,,, 继续