我正在寻找一个简单的AutoHotkey代码来转换点“。”文件名到空格的示例Hamburger.Hill.1987.BluRay.720p.x264
需要转换为Hamburger Hill 1987 BluRay 720p x264
。
以字符串开头:Hamburger.Hill.1987.BluRay.720p.x264.mov
结果字符串:Hamburger Hill 1987 BluRay 720p x264.mov
请注意,应保留扩展名之前的点。
然后在单独的操作中,删除4位数年份后的字符串。此操作还应删除文件扩展名。
以字符串开头:Hamburger Hill 1987 BluRay 720p x264.mov
结果字符串:Hamburger Hill 1987.mov
这是我的代码
#.:: ; Replace all "." (except before extension) with spaces
OldCLip := ClipboardAll
Clipboard := ""
Send ^c
ClipWait, .2
; MsgBox % Clipboard ; for testing
if Clipboard FileMove, % Clipboard, % RegExReplace(Clipboard, "\.(?=.*?\.[^.]+$)", " ")
Clipboard := OldClip
return
我仔细观察但看不到与此相关的代码。在此先感谢您的帮助。
答案 0 :(得分:0)
在AutoHotKey中,您可以使用以下内容:
; set the value
String := "Hamburger.Hill.1987.BluRay.720p.x264.mov"
; capture the extension
RegexMatch(String, "(.*)(\.[^.]*?$)", SubPart)
Filename := SubPart1
Extension := SubPart2
; replace all the dots with spaces
Output1 := RegexReplace(Filename, "\.", " ")
; remove the unwanted characters after the year
Output2 := RegexReplace(Output1, "(?<=\d{4}).*", "")
strMessage := ""
, strMessage .= "String = '" . String . "'
, strMessage .= "`nOutput1 = '" . Output1 . Extension "'
, strMessage .= "`nOutput2 = '" . Output2 . Extension "'
MsgBox, % strMessage
示例输出
String = 'Hamburger.Hill.1987.BluRay.720p.x264.mov'
Output1 = 'Hamburger Hill 1987 BluRay 720p x264.mov'
Output2 = 'Hamburger Hill 1987.mov'
#.:: ; Replace all "." (except before extension) with spaces
OldCLip := ClipboardAll
Clipboard=
Send ^c
ClipWait
; MsgBox % Clipboard ; for testing
; set the value
String := Clipboard
; String := "Hamburger.Hill.1987.BluRay.720p.x264.mov"
; capture the extension
RegexMatch(String, "(.*)(\.[^.]*?$)", SubPart)
Filename := SubPart1
Extension := SubPart2
; replace all the dots with spaces
Output1 := RegexReplace(Filename, "\.", " ")
; remove the unwanted characters after the year
Output2 := RegexReplace(Output1, "(?<=\d{4}).*", "")
; strMessage := ""
; , strMessage .= "String = '" . String . "'
; , strMessage .= "`nOutput1 = '" . Output1 . Extension "'
; , strMessage .= "`nOutput2 = '" . Output2 . Extension "'
; MsgBox, % strMessage
if ( String ) {
strMessage := "Renaming '" . Output1 . Extension . "' to '" . Output2 . Extension . "'"
MsgBox, % strMessage
FileMove, % Output1 . Extension, % Output2 . Extension
} ; end if
Clipboard := OldClip
return