TA的每日心情 | 难过 2015-9-21 13:50 |
---|
签到天数: 4 天 连续签到: 1 天 [LV.2]测试排长
|
以前有个帖子这样写的,不去翻了,脚本如下:
【查找文件是否存在于“某目录或其子目录”的问题】
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 |
|