找回密码
 加入
搜索
查看: 575|回复: 6

[网络通信] 【已解决】请问路径含通配符怎么判断文件是否存在??

[复制链接]
发表于 2022-12-22 20:36:59 | 显示全部楼层 |阅读模式
本帖最后由 229989799 于 2022-12-23 14:05 编辑

举个栗子:
例如某软件路径是;***星号部分是存在不同版本,需要运行它去卸载软件;
$aPath = "C:\Program Files (x86)\Kingsoft\WPS Office\*****\utility\uninst.exe"

FileExist($aPath) ;不支持星号路径。求助一下论坛的热心网友;先谢谢大家啦;
发表于 2022-12-22 21:07:58 | 显示全部楼层
可以先 FileFindFirstFile('C:\Program Files (x86)\Kingsoft\WPS Office\*') ...
 楼主| 发表于 2022-12-22 23:20:37 | 显示全部楼层
不是很会用A版说的FileFindFirstFile函数;在目录下有多个文件夹,需判断哪个文件夹里面才有uninst.exe;然后run它。
举个路径栗子:
C:\Program Files (x86)\Kingsoft\WPS Office\11.8.2.11718\utility\uninst.exe
C:\Program Files (x86)\Kingsoft\WPS Office\11.8.2.11739\utility\uninst.exe
C:\Program Files (x86)\Kingsoft\WPS Office\***********\utility\uninst.exe
发表于 2022-12-23 08:33:15 | 显示全部楼层
按照a版的方法,遍历文件夹下面所有的文件,找到uninst.exe,然后运行。
发表于 2022-12-23 11:54:19 | 显示全部楼层
#include <Array.au3>
Local $aFile = _FileFind('C:\Program Files (x86)\Kingsoft\WPS Office\*', '\utility\uninst.exe')
_ArrayDisplay($aFile)

Func _FileFind($sPath, $sFile)
        Local $hSearch = FileFindFirstFile($sPath)
        If $hSearch = -1 Then Return MsgBox(0, '', '错误: 没有匹配的文件/目录.')
        Local $aPath = StringRegExp($sPath, '^(.*)([^\\]*[\*\?][^\\]*)$', 1)
        If @error Then Return MsgBox(0, '', '搜索格式错误')
        If $aPath[0] = '' Then $aPath[0] = @ScriptDir & '\'
        Local $sFileName, $sList = ''
        While 1
                $sFileName = FileFindNextFile($hSearch)
                If @error Then ExitLoop
                If @extended And FileExists($aPath[0] & $sFileName & $sFile) Then $sList &= $aPath[0] & $sFileName & $sFile & @CRLF
        WEnd
        FileClose($hSearch)
        If $sList = '' Then Return MsgBox(0, '', '错误: 没有找到匹配的文件.')
        Return StringRegExp($sList, '\V+', 3)
EndFunc   ;==>_FileFind

点评

谢谢版主  发表于 2022-12-23 14:03

评分

参与人数 1金钱 +10 收起 理由
229989799 + 10 很给力!

查看全部评分

 楼主| 发表于 2022-12-23 13:57:38 | 显示全部楼层
A版UDF比较实用。

自己摸索的差太远了。
#include <WinAPIShPath.au3>
$sPath = FileFindFirstFile("C:\Program Files (x86)\Kingsoft\WPS Office\*")
    While 1
        $aSearch = FileFindNextFile($sPath)
        If @error Then ExitLoop
                $result = "C:\Program Files (x86)\Kingsoft\WPS Office"&$aSearch&"\utility\uninst.exe"
                If FileExists($result) then ConsoleWrite($result & @CRLF)
    WEnd
FileClose($sPath)

您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-25 16:23 , Processed in 0.072159 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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