Autohotkey to convert dot “.” to space

穿精又带淫゛_ 提交于 2019-12-24 16:09:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!