专注于自动化测试,性能测试.......
判断文件/文件夹是否存在
上一篇 /
下一篇 2008-08-26 22:13:29
/ 个人分类:Vbscript
51Testing软件测试网Ou5uT0Y4O&|E!b&m 在日常测试中,可能需要判断生成的文书或者文件夹是否正确存在,而手工去一一验证则工作量比较大而且枯燥。利用脚本实现就比较方便了。具体如下:
Z.P.A1N0{0以下是具体的实现代码:
p$w\(y|AJ0f5ntU0Set ōbjFSO = CreateObject("scrīpting.FileSystemObject")51Testing软件测试网Tk1[] rg;K,u;W? fq
If objFSO.FolderExists("C:\scrīpts") Then
i9bT3O5r8S0 Wscrīpt.Echo "The folder exists."
8F#t V Ir0Else
)r m0X(q9|h]q0 Wscrīpt.Echo "The folder does not exist."51Testing软件测试网8SYH\IBn8B&T
End If
判断是否存在指定文件
Set ōbjFSO = CreateObject("scrīpting.FileSystemObject")51Testing软件测试网 W/[U4~)|'o!w
If objFSO.FileExists("C:\scrīpts.txt") Then
$z)dem/e@_%C0 Wscrīpt.Echo "The file exists."51Testing软件测试网/K;f
]2U@'D
E
Else
4|C$f4w
hc7z G0 Wscrīpt.Echo "The filedoes not exist."51Testing软件测试网3ra!~7P&@vWJ[
End If
而如果文件夹在远程计算机上,则可以利用以下语句实现:
strComputer = "atl-ws-01"//计算机名51Testing软件测试网eu;mr1ZG
Set ōbjWMIService = GetObject _51Testing软件测试网7o/S-i2U.e h#QDz.K'_
("winmgmts:\\" & strComputer & "\root\cimv2")51Testing软件测试网4@j/X
nD4^7i z
Set colFolders = objWMIService.ExecQuery _
4w2q,t*}y7X5GyR6r0 ("Select * From Win32_Directory Where " & _51Testing软件测试网0Af;e(sV
"Name = 'C:\\scrīpts'")
+K&Xyr8~P E
?0Wscrīpt.Echo colFolders.Count
如果不知道文件生成的路径,则可以:
strComputer = "atl-ws-01"
:\;V yAm&vDT0Set ōbjWMIService = GetObject _
HP-fT:I0 ("winmgmts:\\" & strComputer & "\root\cimv2")51Testing软件测试网&Mkl7DJ6?A-Yj+q
Set colFolders = objWMIService.ExecQuery _51Testing软件测试网Ne{xcz
("Select * From Win32_Directory Where " & _
3KS?;ngBot7_0 "FileName = 'scrīpts'")51Testing软件测试网XQ7ADP!`s
Wscrīpt.Echo colFolders.Count
收藏
举报
TAG:
每日脚本