2016-06-21 33 views
0

1.在文件夾「2」中,我想用Notepad ++打開選定的「example.html」文件。或2鼠標按鍵 - >編輯用記事本++AutoHotkey - 用Notepad ++打開html文件,然後查找並替換,然後保存,關閉。將其包含在另一個腳本中

2.然後查找單詞「大」和「小」取代它,保存並退出記事本++,並返回到文件夾「2」。

當選擇html文件時 - 單個快捷鍵如何實現2個第一步。沒有將它實現到另一個腳本中。

3.以及如何使用此腳本實現上述腳本,然後將其壓縮並移動到「FINAL」文件夾。因爲其中的一個文件是HTML文件,我需要執行上述兩個步驟。我想腳本應該在「發送^ a;全選」部分之前開始。

#IfWinActive ahk_class CabinetWClass 

F4:: 
for window in ComObjCreate("Shell.Application").Windows 
try Fullpath := % window.Document.Folder.Self.Path 
IfNotExist, %Fullpath%\1\2 
{ 
MsgBox, The folder "%Fullpath%\1\2" doesn't exist 
    return 
} 
Run, %Fullpath%\1\2 
WinWait, %Fullpath%\1\2 
WinActivate, %Fullpath%\1\2 
WinWaitActive,%Fullpath%\1\2 
StringReplace, Fullpath2, Fullpath, :, 
StringSplit, folder_array, Fullpath2, \, 
FolderName = % folder_array%folder_array0% 
; MsgBox, % folder_array%folder_array0% 
; Sleep 2000  ; wait 2 seconds 
Send ^a     ; Select All 
Send, {AppsKey}   ; Press the "context menu" key 
Sleep 100 
Send n    ; Select "Send to" with the "n" key 
Sleep 100 
Send {Right}   ; Open "Sent to" with the "right arrow" key 
Sleep 100 
Send {Down}    ; Select "Compressed (zipped) folder" with the "arrow down" key 
Sleep 100 
Send {Enter}   ; Execute "Compressed (zipped) folder" with the  "Enter" key 
    Sleep 2000  ; wait 2 seconds 
    SendInput, % folder_array%folder_array0% 
    Send {Enter} 
SetTimer, Move_ZIP, 500 
return 

#IfWinActive 

Move_ZIP: 
FileCreateDir %A_Desktop%\FINAL 
IfExist, %Fullpath%\1\2\%FolderName%.zip 
{ 
SetTimer, Move_ZIP, off 
FileMove, %Fullpath%\1\2\%FolderName%.zip, %A_Desktop%\FINAL 
Sleep 2000  ; wait 2 seconds 
SetTimer, CopyDir, 500 
} 
return 

CopyDir: 
IfExist, %Fullpath%\1\2\%FolderName%.zip 
return 
SetTimer, CopyDir, off 
FileCopyDir %Fullpath%\1\2, %A_Desktop%\FINAL\%FolderName% 
return 
+0

有東西像'FileOpen'和'StringReplace'在AHK。你不需要打開任何外部程序(記事本)來解析和替換文件內容 – Blauhirn

+0

根據你要做的事情,使用腳本語言會更簡單(** Perl **或** Python * *)替換內容,並啓動一個壓縮工具(例如** 7zip **)。你也可以從AHK啓動這個腳本。 –

回答

0
; ... 

WinWait, %Fullpath%\1\2 
WinActivate, %Fullpath%\1\2 
WinWaitActive,%Fullpath%\1\2 

FileRead, Contents, %Fullpath%\1\2\example.html 
if not ErrorLevel ; Successfully loaded 
{ 
    StringReplace, Contents, Contents, big, small ; replace only the first occurrence 
    ; OR : 
    ; StringReplace, Contents, Contents, big, small, All ; replace all occurrences 
    FileAppend, %Contents%, %Fullpath%\1\2\example2.html 
    Contents = ; Free the memory 
} 
FileMove, %Fullpath%\1\2\example2.html, %Fullpath%\1\2\example.html, 1 ; overwrite existing file 

StringReplace, Fullpath2, Fullpath, :, 
; ... 

https://autohotkey.com/docs/commands/FileRead.htm

https://autohotkey.com/docs/commands/StringReplace.htm

https://autohotkey.com/docs/commands/FileAppend.htm

+0

Thanx,它的工作原理!我有點難以完全理解AutoHotkey變量和它們之間的相互作用。已經嘗試了幾個小時,但對於更具體的任務,這對我來說很頭疼。 – Curioucity

相關問題