问题
I am looking for a simple AutoHotkey Code to convert dot "." of file name to space Example Hamburger.Hill.1987.BluRay.720p.x264
needs to be converted to Hamburger Hill 1987 BluRay 720p x264
.
Start with string: Hamburger.Hill.1987.BluRay.720p.x264.mov
Result String: Hamburger Hill 1987 BluRay 720p x264.mov
Note the dot before the extension should be retained.
Then in a separate operation, remove the string of characters following the 4 digit year. This operation should also remove the file extension.
Start with string: Hamburger Hill 1987 BluRay 720p x264.mov
Result String: Hamburger Hill 1987.mov
Here is my code
#.:: ; 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
I looked throughly but could not see code related to this. Thanks in advance for your help.
回答1:
In AutoHotKey you'd use something like this:
; 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
Sample output
String = 'Hamburger.Hill.1987.BluRay.720p.x264.mov'
Output1 = 'Hamburger Hill 1987 BluRay 720p x264.mov'
Output2 = 'Hamburger Hill 1987.mov'
How I would incorporate that into your script.
#.:: ; 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
来源:https://stackoverflow.com/questions/36879927/autohotkey-to-convert-dot-to-space