軟件測試工具QTP:FileSystemObject基礎知識

發表于:2009-05-26來源:作者:點擊數: 標簽:軟件測試工具qtpQTP知識
在 QTP 測試 中,比較本地的兩個文件是不是相同,需要使用 VB Script的FileSystemObject對象,在此作簡要的概述 一.基礎FileSystemObject 1.創建FileSystemObject對象 Dimfso Setfso=CreateObject(\"Scripting.FileSystemObject\") Scripting是類型庫的名字
QTP測試中,比較本地的兩個文件是不是相同,需要使用VBScript的FileSystemObject對象,在此作簡要的概述
一.基礎FileSystemObject
1.     創建 FileSystemObject 對象
Dim fso
Set fso = CreateObject(\"Scripting.FileSystemObject\")
  Scripting 是類型庫的名字,而 FileSystemObject 則是想要創建的對象的名字。
  要用 FileSystemObject (FSO) 對象模式來編程,則:使用 CreateObject 方法來創建 FileSystemObject 對象。 
  FSO 對象模式包含在 Scripting 類型庫中,該庫位于 Scrrun.dll 文件中。因而,要使用 FSO 對象模式,必須把 Scrrun.dll 放在 Web 服務器的適當系統目錄中。
2.     使用方法:
  訪問現有驅動器、文件和文件夾
GetDrive()、GetFolder()、GetFile()、CreateFolder()、CreateFile()、CreateTextFile ()、OpenTextFile()、FolderExists(url)、DeleteFolder(url)、MoveFolder(src,to)、FileExists(url)、CopyFile()、MoveFile()、DeleteFile()、
例如:
Dim fso, f1
Set fso = CreateObject(\"Scripting.FileSystemObject\")
Set f1 = fso.GetFile(\"c:\\test.txt\")
3.     訪問屬性:
Name、Path、Size、Type、DateLastModified(上一次修改的文件時間)
二.FSO的一些特殊功能
1.        GetSpecialFolder Method 返回特定的Windows文件夾的路徑:
  Windows安裝目錄;Windows系統目錄;Windows臨時目錄 
  FSO.GetSpecialFolder([0, 1, or 2])  
2.        GetTempName Method 返回一個隨機產生的文件或者目錄名字,用于存儲臨數據
3.        GetAbsolutePathName Method 返回文件夾的絕對路徑(類似于Server.MapPath)。
比如,FSO.GetAbsolutePathName(\"region\") 將返回類似于下面的結果:\"c:mydocsmyfolder egion\" 
4.        GetExtensionName Method 返回路徑中最后部分的擴展名 (比如:FSO.GetExtensionName(\"c:docs est.txt\") 將返回txt) 
5.        GetBaseName and GetParentFolder Methods 返回路徑中最后部分的父文件夾 (比如:FSO.GetParentFolder (\"c:docsmydocs\") 將返回’docs’) 
6.        Drives Property 返回所有本地可用驅動器的集合,用于建立資源瀏覽器樣的用戶接口。

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97