51Testing软件测试论坛

标题: 如何获得被测系统.exe文件的路径 [打印本页]

作者: smalliv4125    时间: 2009-8-25 17:42
标题: 如何获得被测系统.exe文件的路径
如题,如何用vbs编写几句代码实现寻找被测系统.exe文件(比如:aaa.exe)的路径。请高手告知。谢谢
作者: lvguobin    时间: 2009-8-25 17:46
我记得有这样的API你可以自己去找一下。
作者: fei.ge    时间: 2009-8-25 22:44
以前有个帖子这样写的,不去翻了,脚本如下:

【查找文件是否存在于“某目录或其子目录”的问题】

foldername =  "G:\Test2"
filename ="标准版测试用例_new.xls"
Dim find,temp
find = False
call FindFilePath(foldername,filename)
msgbox temp   

'在foldername文件夹及其子文件夹下找到一个名字为filename的文件的路径
Function FindFilePath(foldername,filename)                        
        Dim fso,UtilFolder,UtilFolderCollection
        Dim tpath

        Set fso = CreateObject("Scripting.FileSystemObject")         
'        On error resume next
        Set UtilFolder=fso.GetFolder(foldername)
        If  UtilFolder is nothing Then
                msgbox "FindFilePath的foldername参数不正确"
        End If
        '搜索当前所有子目录
                If not find Then
                            For each f in UtilFolder.files
                                        If StrComp(Lcase(f.name),Lcase(trim(filename))) = 0 Then
                        find = True
                        tpath = f.path
                                                temp = Cstr(tpath)
                        Exit For
                                        End If
                                Next
                End If

               
        If not  find Then
                Set UtilFolderCollection = UtilFolder.SubFolders
                If Not UtilFolderCollection Is Nothing Then                '如果子目录不为空
                        For each ufolder in UtilFolderCollection
                                 FindFilePath ufolder,filename
                        Next
                End If
        Else

        End If
        Set UtilFolder = Nothing
        Set UtilFolderCollection = Nothing
        Set fso = Nothing
End Function




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2