lorrell 发表于 2014-3-25 16:22:03

如何让input输入框自动按行获取本地txt文件(已解决)

本帖最后由 lorrell 于 2014-3-26 15:06 编辑



我的目的是让输入框自动获取本地txt文件里的内容,然后点ok键,会让指定浏览器自动打开txt中的网络地址

haijie1223 发表于 2014-3-25 21:07:37

本帖最后由 haijie1223 于 2014-3-25 23:44 编辑

看错题目了,FileReadLine()-GUICtrlSetData()-ShellExecute(GUICtrlRead())

半芯竹 发表于 2014-3-25 21:15:40

FileReadLine()
上面是读取文本,以下是打开网址
ShellExecute(‘’网址')

fuldho 发表于 2014-3-26 08:20:08

回复 1# lorrell


    #Include <File.au3>

Local $file = FileOpen("test.txt", 0);要打开的文件
; 检查打开的文件是否可读
If $file = -1 Then
        MsgBox(4096, "错误", "不能打开文件.")
        Exit
EndIf
Local $Lines = _FileCountLines("test.txt") ;返回指定文件的总行数

for $I = 1 To $Lines Step 1               ;按文本行数赋值给 $I                  

$line = FileReadLine($file)

InputBox("读取", "读取第 "& $I &"行: ", $Line); 每次读取一行文本,直到文件结束.

Next

FileClose($file) ;关闭文本

lorrell 发表于 2014-3-26 10:24:17

回复 3# 半芯竹

再请教一下,怎么让ShellExecute循环呢 ,我想要的效果是文本里的所有网址一次性都打开

haijie1223 发表于 2014-3-26 10:30:02

回复 5# lorrell


    一次性全打开。。。
ShellExecute("网址1")
ShellExecute("网址2")
...
ShellExecute("网址n")
至于网址怎么获取用搜索一下网址正则吧~

skyfree 发表于 2014-3-26 11:49:35

txt内容发上来做个示范,要不只能瞎猜了。

lorrell 发表于 2014-3-26 12:32:08

回复 7# skyfree

就是这两个文档,我想要的效果是点击ok按钮后,让这两个浏览器同时打开website里的所有网页

afan 发表于 2014-3-26 12:50:55

回复skyfree

就是这两个文档,我想要的效果是点击ok按钮后,让这两个浏览器同时打开website里的所有网 ...
lorrell 发表于 2014-3-26 12:32 http://www.autoitx.com/images/common/back.gif


    你这要求不需要界面,或者1#的界面没啥用

lorrell 发表于 2014-3-26 13:17:48

回复 9# afan

那怎么写啊

半芯竹 发表于 2014-3-26 13:33:52

回复 10# lorrell


    先自己动手写写看嘛。 多练习才能进步,不要总是想着拿来主义。。

lorrell 发表于 2014-3-26 13:41:29

回复 11# 半芯竹

下边这个是我写的 现在输入框里可以按行显示网页地址,但是执行的时候并没有按行执行 都变成一个网址了 这是为什么啊

Global $filePath = "./browers.txt"
Global $COUNT = 30
Global $websitePath = "./website.txt"

$website = FileOpen("website.txt", 0)
; 检查文件是否正常打开
If $website = -1 Then
    MsgBox(0, "错误", "无法打开目标文件。")
    Exit
EndIf

main()
Func main()
        Local $GUIWidth = 320, $GUIHeight = 200
        Global $ParentWin, $browers[$COUNT]
        $ParentWin = GUICreate("browers测试工具", $GUIWidth, $GUIHeight)
        $web = GUICtrlCreateEdit("测试网址", 10, 5, 300, 150)
        $btn = GUICtrlCreateButton("Ok", 100,160, 90, 30)
      $edittext = FileRead($website)
      GUICtrlSetData($web,$edittext)

         $lines = FileReadLine($website)
         FileClose($website)
         GUISetState()

        While 1
      $msg = GUIGetMsg()
                Select
                        Case $msg = $GUI_EVENT_CLOSE
                                ExitLoop
                        Case $msg = $btn
                                $browers = readBrowersOf($filePath)
                                ext($browers, GUICtrlRead($web))
                EndSelect
    WEnd
    GUIDelete()

EndFunc

;运行读取到的程序
Func ext($where, $url)
        WinMinimizeAll ( )
        FOR $item IN $where
                Dim $path = String($item)
                If IsString($path) And StringLen($path) > 0 Then
                        If FileExists($path) Then
                                Local $pro = ShellExecute($path, $url)
                        EndIf
                EndIf
        NEXT
EndFunc


;读取浏览器的地址
Func readBrowersOf($where)
        $lines = FileOpen($where)
        Dim $rs_count = 0
        Dim $results[$COUNT]

        While 1
                $line = FileReadLine($lines)
                If @error = -1 Then ExitLoop
                If StringLen($line)Then
                        $results[$rs_count] = $line
                        $rs_count = $rs_count + 1

                EndIf
        Wend
        FileClose($lines)

        Return $results
EndFunc

afan 发表于 2014-3-26 14:04:49

无界面Local $aBrowers = StringRegExp(FIleRead('Browers.txt'), '(?mi)^\h*(\w:\V+?\.exe)\s*$', 3)
If @Error Then Exit MsgBox(48, '', '获取浏览器路径失败')
Local $aWebsite = StringRegExp(FIleRead('Website.txt'), '(?mi)^\h*((?:\w+://|\w+\.)\S+)\s*$', 3)
If @Error Then Exit MsgBox(48, '', '获取网址失败')
Local $i, $j
For $i = 0 To UBound($aBrowers) - 1
        For $j = 0 To UBound($aWebsite) - 1
                Run('"' & $aBrowers[$i] & '" "' & $aWebsite[$j] & '"')
        Next
Next

lorrell 发表于 2014-3-26 14:37:57

回复 13# afan
厉害!!!!{:face (293):}完全木有问题

skyfree 发表于 2014-3-26 14:58:14

回复 8# lorrell


    的确是连界面都不需要,直接就是运行就打开所有记事本里的网址不就行了?还用复制到文本框里?
页: [1] 2
查看完整版本: 如何让input输入框自动按行获取本地txt文件(已解决)