找回密码
 加入
搜索
查看: 6096|回复: 3

[AU3基础] 搜索文件内代码$stt=$array[UBound($array)-1]求解释

[复制链接]
发表于 2012-3-16 14:05:39 | 显示全部楼层 |阅读模式
悬赏20金钱已解决
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#NoTrayIcon
$Form1 = GUICreate("递归遍历文件", 660, 369, 191, 121)
$List1 = GUICtrlCreateList("", 0, 8, 649, 266)
$Button1 = GUICtrlCreateButton("查找文件名演示", 248, 280, 153, 33, 0)
$Button2 = GUICtrlCreateButton("查找后缀名文件演示", 32, 280, 161, 33, 0)
$Button3 = GUICtrlCreateButton("遍历所有文件演示", 448, 280, 153, 33, 0)
$Label1 = GUICtrlCreateLabel("搜索状态", 16, 336, 636, 17)
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case  $Button3
                        GUICtrlSetData($Label1,"搜索中....")
                        $patch="c:"
                        seachfile($patch,"*");;;;;;;;;;;遍历所有文件
                        GUICtrlSetData($Label1,"搜索完成")                
                Case  $Button2
                
                        GUICtrlSetData($Label1,"搜索中....")
                        $patch="c:"
                        seachfile($patch,"*","dll");;;;演示查找DLL后缀名文件;
                        GUICtrlSetData($Label1,"搜索完成")
                        
                Case  $Button1
                        GUICtrlSetData($Label1,"搜索中....")
                        $patch="c:"
                        seachfile($patch,"*","explorer.exe");;;;;;;;;查找文件名        
                        GUICtrlSetData($Label1,"搜索完成")
        
EndSwitch
        
WEnd

Func seachfile($patch,$str,$mask="")
Local $search,$file,$array,$array2,$stt,$stt2
$search = FileFindFirstFile($patch&$str)  
If $search  Then
While 1        
        $file = FileFindNextFile($search) 
        If @error Then ExitLoop
        $array=StringSplit($file,".")
        $array2=StringSplit($file,"/")
        $stt=$array[UBound($array)-1]
        $stt2=$array2[UBound($array2)-1]
        if $mask<>"" Then
       if $stt=$mask  or $stt2=$mask Then
                   GUICtrlSetData($List1,$patch&$file)                 
                   GUICtrlSetData($Label1,$patch&$file)
           EndIf           
   Else          
                GUICtrlSetData($List1,$patch&$file)        
                GUICtrlSetData($Label1,$patch&$file)
        EndIf                
                if FileChangeDir( $patch&$file)=1 and $file<>"." and $file<>".." Then
                        seachfile($patch&$file&"",$str,$mask)                                
 EndIf

WEnd
FileClose($search)
EndIf

EndFunc
这是某大哥写的搜索文件的例子。。。小弟新手。。对其中有些不明白。。求高人解释
$array=StringSplit($file,".")
        $array2=StringSplit($file,"/")
        $stt=$array[UBound($array)-1]
        $stt2=$array2[UBound($array2)-1]
这该如何解释。。。用法?

最佳答案

查看完整内容

$file里存放的字符串 用 . 来分割 成数组 $array 比如 $file = "www.baidu.com" $array = StringSplit($file,".") 这样就得到 $array[0] = 3 , 拆成了几段 $array[1] = "www" $array[2] = "baidu" $array[3] = "com" 同理 $array2=StringSplit($file,"/") 是用 / 来分割 UBound 函数用来得到 数组维度的大小. 例如 Dim $array[10] 定义一个含有10个元素的一位数组 ($array[0]、$array[1]、.......、$array[9]) UBound($ar ...

评分

参与人数 1金钱 +20 收起 理由
afan + 20 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2012-3-16 14:05:40 | 显示全部楼层
$file里存放的字符串 用 .  来分割 成数组 $array

比如  $file = "www.baidu.com"
$array = StringSplit($file,".")
这样就得到 $array[0] = 3 , 拆成了几段
$array[1] = "www"
$array[2] = "baidu"
$array[3] = "com"

同理 $array2=StringSplit($file,"/") 是用  /  来分割
UBound 函数用来得到 数组维度的大小.
例如
Dim $array[10] 定义一个含有10个元素的一位数组 ($array[0]、$array[1]、.......、$array[9])
UBound($array) 即得到 10

所以$stt=$array[UBound($array)-1]
就是 把数组 $array 的最后一个元素的值 给$str

评分

参与人数 1贡献 +10 收起 理由
xyhqqaa + 10 谢谢 .很清晰.我再慢慢理解

查看全部评分

发表于 2014-5-3 23:16:47 | 显示全部楼层
非常谢谢。正迷茫中!解释的很清楚,懂了!谢谢、!真诚的!
发表于 2017-8-3 11:08:16 | 显示全部楼层
谢谢大大们的帮助
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-10 22:23 , Processed in 0.078525 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表