by shendaowu » 24 Mar 2024, 04:47
自己大概解决了,大概是换行惹的祸。
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 := FileList . A_LoopFileName . "`n" ; 这里是不是有问题?
;Sort, FileList, R ; The R option sorts in reverse order. See Sort for other options.
FileDelete, .\manual_sort.txt
FileAppend, %FileList%, .\manual_sort.txt
Run, .\manual_sort.txt
MsgBox,,, 继续
FileRead, newFileList, .\manual_sort.txt
newFileArray := StrSplit(newFileList, "`n")
FileDelete, .\test2.txt
For key, oldFileName in newFileArray{
FileAppend, %oldFileName%`n, .\test2.txt
;oldFileName := Trim(oldFileName, OmitChars = "`n")
oldFileName := StrReplace(oldFileName, "`r", "")
oldFileName := StrReplace(oldFileName, "`n", "")
if(oldFileName = ""){
Continue
}
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%"
;FileAppend, rename "%oldFileName%" "%newFileName%"`n, .\test2.txt
}
MsgBox,,, 继续
自己大概解决了,大概是换行惹的祸。
[Codebox=autohotkey file=Untitled.ahk]#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 := FileList . A_LoopFileName . "`n" ; 这里是不是有问题?
;Sort, FileList, R ; The R option sorts in reverse order. See Sort for other options.
FileDelete, .\manual_sort.txt
FileAppend, %FileList%, .\manual_sort.txt
Run, .\manual_sort.txt
MsgBox,,, 继续
FileRead, newFileList, .\manual_sort.txt
newFileArray := StrSplit(newFileList, "`n")
FileDelete, .\test2.txt
For key, oldFileName in newFileArray{
FileAppend, %oldFileName%`n, .\test2.txt
;oldFileName := Trim(oldFileName, OmitChars = "`n")
oldFileName := StrReplace(oldFileName, "`r", "")
oldFileName := StrReplace(oldFileName, "`n", "")
if(oldFileName = ""){
Continue
}
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%"
;FileAppend, rename "%oldFileName%" "%newFileName%"`n, .\test2.txt
}
MsgBox,,, 继续[/Codebox]