找回密码
 加入
搜索
楼主: 夜猫猫

[AU3基础] 如何获取已知程序所在的文件夹名?(已解决)16楼全码

 火.. [复制链接]
 楼主| 发表于 2011-7-18 20:48:21 | 显示全部楼层
本帖最后由 夜猫猫 于 2011-7-18 21:09 编辑
难道要这个?
kevinch 发表于 2011-7-18 20:20



对.就是这个..谢谢 kevinch

查找文件夹中所有的EXE文件.返回文件所在的目录名,写入INI文件中

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 564, 227, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 88, 72, 233, 21)
$Button1 = GUICtrlCreateButton("...", 336, 72, 57, 25)
$Button2 = GUICtrlCreateButton("Button1", 232, 144, 97, 33)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        Case $Button1
     $file = FileSelectFolder("选择文件夹.", "")
         GUICtrlSetData($Input1,$file)
 Case $Button2
         _Seachfilebyext(GUICtrlRead($Input1), 'exe')
        EndSwitch
WEnd

Func _Seachfilebyext($current, $ext)
        Local $search = FileFindFirstFile($current & "\*.*")
        While 1
                Dim $file = FileFindNextFile($search)
                If @error Or StringLen($file) < 1 Then ExitLoop
                If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
                        If StringRight($current & "\" & $file, StringLen($ext)) = $ext Then
                                                                $Filepath = $current & "\" & $file
                                                                ;msgBox(0, '', $Filepath)
                                                                $a_Arr=StringSplit($Filepath,"\")
                                $fileinfo = $a_Arr[UBound($a_Arr)-2]
                                                                $u = $fileinfo&"="&$Filepath
                                                                $h=FileWrite(@ScriptDir&"\log.ini",$u& @CRLF) 
                        EndIf
                EndIf
                If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
                        _Seachfilebyext($current & "\" & $file, $ext)
                                        EndIf
                
        WEnd
EndFunc   ;==>
发表于 2011-7-18 21:04:19 | 显示全部楼层
回复 14# 夜猫猫

不要路径全名?把返回值改下就行了
发表于 2011-7-18 21:05:27 | 显示全部楼层
Local $Str = 'C:\Windows\System32\cmd.exe'
Local $Test = StringRegExpReplace($str, '.*?\\?([^\\]+)\\[^\\]+$', '\1')
MsgBox(0, '', '原字符串' & @LF & $Str & @LF & @LF & '提取结果' & @LF & $Test)
发表于 2011-7-18 21:07:17 | 显示全部楼层
难道要这个?
kevinch 发表于 2011-7-18 20:20


这个是最简单的
 楼主| 发表于 2011-7-18 21:14:10 | 显示全部楼层
afan

StringRegExpReplace($str, '.*?\\?([^\\]+)\\[^\\]+$', '\1')
中的'\1'代表什么?
能解释下这个正则吗?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-12 18:13 , Processed in 0.069487 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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