Skip to content

Instantly share code, notes, and snippets.

@emisjerry
Created October 20, 2019 07:25
Show Gist options
  • Save emisjerry/d191c18a18eba8ce0878d25156e3cdcd to your computer and use it in GitHub Desktop.
Save emisjerry/d191c18a18eba8ce0878d25156e3cdcd to your computer and use it in GitHub Desktop.
; Generated by AutoGUI 2.5.7
#SingleInstance Force
#NoEnv
#Include d:\util\AutoGUI\convertFile.ahk
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
global aFiles, sInputFolder
aFiles := []
;----- Start of GUI
Gui +Resize
Gui Font, s12, 微軟正黑體
Gui Color, 0xCFFEF7
Gui Font
Gui Font, s14 Bold Underline c0xFF0000
Gui Add, Text, x168 y8 w270 h23 +0x200, 檔案格式轉換工具 v1.0
Gui Font
Gui Font, s12, 微軟正黑體
Gui Add, Text, hWndhTxt2 x16 y72 w242 h23 +0x200, 選擇要轉換的檔案(多選)
Gui Add, Text, x-3 y42 w631 h2 +0x10
Gui Font
Gui Font, s10
Gui Add, Edit, hWndhEdtValue vEdtFiles x264 y56 w221 h60
Gui Font
Gui Font, s12, 微軟正黑體
Gui Font
Gui Font, s10, 細明體
Gui Add, Button, gBtnSelectFiles x496 y56 w110 h60, 選擇檔案...
Gui Font
Gui Font, s12, 微軟正黑體
Gui Add, Text, x16 y144 w242 h23 +0x200, 輸出資料夾
Gui Add, Edit, vEdtOutput x264 y136 w221 h36
Gui Font
Gui Font, s10, 細明體
Gui Add, Button, gBtnSelectOutput x496 y128 w110 h60, 選擇檔案...
Gui Font
Gui Font, s12, 微軟正黑體
Gui Add, Text, x16 y208 w242 h23 +0x200, 輸出格式
Gui Add, ListBox, vLbFormat x264 y208 w222 h129, PDF|DOCX|TXT|HTML|ODF
Gui Add, Button, gExecute x176 y376 w111 h47, &Y 開始轉檔
Gui Add, Button, x336 y376 w111 h47 gClose, &N 關閉
Gui Show, w620 h463, 檔案格式轉換工具 v1.0
;----- End of GUI
Return
BtnSelectFiles:
FileSelectFile, files, M3 ; M3 = Multiselect existing files.
if (files = "") {
;MsgBox, The user pressed cancel.
return
}
sInputFolder := ""
_sSelected := ""
_iCount := 0
Loop, parse, files, `n
{
if (A_Index = 1) {
;MsgBox, The selected files are all contained in %A_LoopField%.
sInputFolder = %A_LoopField%
} else {
_iCount++
;MsgBox, 4, , The next file is %A_LoopField%. Continue?
_sFilename := sInputFolder . "\" . A_LoopField
aFiles.push(_sFilename)
_sSelected := _sSelected . _sFilename . "`n"
IfMsgBox, No, break
}
}
;MsgBox count=%_iCount%
GuiControl,, edtFiles, %_iCount%個檔案: %_sSelected%
Return
BtnSelectOutput:
FileSelectFolder, folder, *C:\Users\%A_UserName%\Documents, 3, 選擇輸出資料夾
if (folder = "") {
;MsgBox, The user pressed cancel.
return
}
GuiControl,, EdtOutput, %folder%
Return
EdtFiles:
Return
Execute:
Gui, Submit
;MsgBox output folder=%EdtOutput%, format=%LbFormat%
; filename含有路徑
for index, filename in aFiles
{
;MsgBox 第[%index%]個檔=%filename%
_iPos := InStr(filename, ".")
_sFilenameWithoutExt := Substr(filename, 1, _iPos)
_sFilenameWithoutExt := StrReplace(_sFilenameWithoutExt, sInputFolder, EdtOutput)
_sOutputFilename := _sFilenameWithoutExt . LbFormat
;MsgBox output filename=%_sOutputFilename%
convertFile(filename, _sOutputFilename)
}
Return
Close:
GuiEscape:
GuiClose:
ExitApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment