[已解决]如何批量添加文本内容到编辑框?然后保存为TXT(有代码)
本帖最后由 731106 于 2011-3-27 21:04 编辑如何批量添加文本内容到编辑框?我写了一段代码(如下),只能一个文本一个文本的添加,如果选择全部文本文件就没反应,还有另存为这个地方应该怎么写?#include <GUIConstants.au3>
;#include <ButtonConstants.au3>
;#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiEdit.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 400, 433, 427, 173)
$Edit1 = GUICtrlCreateEdit("", 152, 8, 200, 393)
GUICtrlSetData(-1, "")
$Label1 = GUICtrlCreateLabel("请选择文件:", 52, 16, 88, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("浏 览", 56, 48, 65, 25)
$Button2 = GUICtrlCreateButton("另存为", 56, 300, 65, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$message = "浏览文件"
$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
$sFile = FileOpenDialog($message, $MyDocsFolder, "文本文件 (*.txt)", 1 + 4)
_GUICtrlEdit_AppendText($Edit1, FileRead($sFile)) ;这个地方只能一个文本一个文本的添加
Case $Button2
$message = "另存为"
$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
$sFile = FileSaveDialog($message, $MyDocsFolder, "文本文件 (*.txt)", 2)
_GUICtrlEdit_GetText($Edit1,FileWrite($sFile)) ;这个地方是错的,应该怎么写?如果能直接生成指定的文本最好,比如:log.txt
EndSwitch
WEnd还有保存窗口的路径如何直接跳到之前浏览文件的路径窗口?在论坛搜索了相关的文章但都找不到好的处理办法 自己解决,重新写了一下代码,很乱,但批量导入还是不行,只有一个个的导,还有保存功能也不好用,只能调出保存窗口,不能保存,但可以直接在目录下生成明细文件
代码如下:#include <GUIConstants.au3>
;#include <ButtonConstants.au3>
;#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiEdit.au3>
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("TXT文件合并 By CFXZ", 600, 433, 427, 173)
$Edit1 = GUICtrlCreateEdit("", 440, 50, 150, 360, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL,$ES_READONLY, $WS_HSCROLL))
$Edit2 = GUICtrlCreateEdit("",30, 50, 400, 360,BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL,$ES_READONLY, $WS_HSCROLL))
$Edit3 =GUICtrlCreateEdit("",520, 15, 70, 20,$ES_READONLY)
GUICtrlSetData(-1, "")
$Label1 = GUICtrlCreateLabel("请选择代码文件:", 22, 16, 120, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("代码个数共:", 430, 16, 90, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("浏 览", 150, 16, 65, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$message = "浏览文件"
;$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
$sFile = FileOpenDialog($message, @WorkingDir, "文本文件 (*.txt)", 1 + 4)
_GUICtrlEdit_AppendText($Edit1, FileRead($sFile)) ;这个地方只能一个文本一个文本的添加
;WinActivate("合并TXT文件", "")
$var = ControlGetText("TXT文件合并 By CFXZ", "", "Edit1")
;MsgBox(4096,"",$var)
$file = FileOpen('hs.txt', 2 + 8)
FileWriteLine ($file,$var)
$a = FileGetLongName($sFile)
_GUICtrlEdit_AppendText($Edit2,$a & @LF)
;MsgBox(4096,"",$a)
$b = ControlCommand("TXT文件合并 By CFXZ", "", "Edit1", "GetLineCount", "")
_GUICtrlEdit_SetText($Edit3,$b-1)
;MsgBox(4096,"",$b)
;Case $Button2
;$message = "另存为"
;$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
;$sFile = FileSaveDialog($message, $MyDocsFolder, "文本文件 (*.txt)", 2)
EndSwitch
WEnd
页:
[1]