qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          QTP自動化測試-TXT文件操作

           創建文本文件
            Set bjFSO = CreateObject("Scripting.FileSystemObject")
            Set bjFile = objFSO.CreateTextFile("C:\FSOScriptLog.txt")
            檢察文件是否存在
          Set bjFSO = CreateObject("Scripting.FileSystemObject")
          If objFSO.FileExists("C:\FSOScriptLog.txt") Then
          Set bjFolder = objFSO.GetFile("C:\FSOScriptLog.txt")
          Else
          MsgBox "File does not exist."
          End If
            刪除文本文件
            Set bjFSO = CreateObject("Scripting.FileSystemObject")
            objFSO.DeleteFile("C:\FSOScriptLog.txt")
            移動文件
            Set bjFSO = CreateObject("Scripting.FileSystemObject")
            objFSO.MoveFile "C:\FSOScriptLog.txt" , "D:\"
            復制文件
            Set bjFSO = CreateObject("Scripting.FileSystemObject")
            objFSO.CopyFile "C:\FSOScriptLog.txt" , "D:\"
            重命名文件
            Set bjFSO = CreateObject("Scripting.FileSystemObject")
            objFSO.MoveFile "C:\FSO\ScriptLog.txt" , "C:\FSO\BackupLog.txt"
            讀取全部內容
          Const ForReading = 1
          Set bjFSO = CreateObject("Scripting.FileSystemObject")
          Set bjFile = objFSO.OpenTextFile("C:ScriptsTest.txt", ForReading)
          strContents = objFile.ReadAll
          Wscript.Echo strContents
          objFile.Close
            一行行的讀取文本文件內容
          Const ForReading = 1
          Set bjFSO = CreateObject("Scripting.FileSystemObject")
          Set bjTextFile = objFSO.OpenTextFile ("C: \ScriptsTest.txt", ForReading)
          Do Until objTextFile.AtEndOfStream
          strComputer = objTextFile.ReadLine
          Wscript.Echo strComputer
          Loop
          objTextFile.Close
           追加文本文件一行內容
          Const ForAppending = 8
          Set bjFSO = CreateObject("Scripting.FileSystemObject")
          Set bjTextFile = objFSO.OpenTextFile ("C:\ScriptsTest.txt ", ForAppending, True)
          objTextFile.WriteLine("追加的內容")
          objTextFile.Close
            有用的幾個函數:
            替換:將Jim替換成James。
            strNewText = Replace(strText, "Jim ", "James ")
            用逗號分隔字符串:
            arrpath=split(strDN,",")
            wscript.echo arrpath(0)
            讀取文本文件指定的行內容(讀第四行內容存到strLine變量中)
          Const ForReading = 1
          Set bjFSO = CreateObject("Scripting.FileSystemObject")
          Set bjTextFile = objFSO.OpenTextFile("C:\ScriptsTest.txt ", ForReading)
          For i = 1 to 3
          objTextFile.ReadLine
          Next
          strLine = objTextFile.Readline
          MsgBox strLine
          objTextFile.Close
            查看文件屬性
          Set bjFSO = CreateObject("Scripting.FileSystemObject")
          Set bjFile = objFSO.GetFile("c:\ScriptsTest.txt")
          msgbox "Date created: " & objFile.DateCreated
          msgbox "Date last accessed: " & objFile.DateLastAccessed
          msgbox "Date last modified: " & objFile.DateLastModified
          msgbox "Drive: " & objFile.Drive
          msgbox "Name: " & objFile.Name
          msgbox "Parent folder: " & objFile.ParentFolder
          msgbox "Path: " & objFile.Path
          msgbox "Short name: " & objFile.ShortName
          msgbox "Short path: " & objFile.ShortPath
          msgbox "Size: " & objFile.Size
          msgbox "Type: " & objFile.Type
            修改文件屬性
          Set bjFSO = CreateObject("Scripting.FileSystemObject")
          Set bjFile = objFSO.GetFile("C:\ScriptsTest.txt")
          If objFile.Attributes AND 1 Then
          objFile.Attributes = objFile.Attributes XOR 1
          End If
            寫入文本文件
          Const ForWriting=2
          Set bj=createobject("scripting.filesystemobject")
          Set bjfile=obj.opentextfile("C:\ScriptsTest.txt", ForWriting)
          objfile.write("This is line 1.")
          objfile.writeline("This is line2.")
          objfile.close
          版權聲明:本文出自 wpt1987 的51Testing軟件測試博客:http://www.51testing.com/?365260

          posted on 2014-04-15 10:55 順其自然EVO 閱讀(888) 評論(0)  編輯  收藏 所屬分類: qtp

          <2014年4月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 万源市| 铅山县| 浪卡子县| 延寿县| 霍城县| 洛宁县| 阿拉善右旗| 绩溪县| 敦煌市| 环江| 新源县| 明水县| 太康县| 小金县| 屏东县| 班戈县| 科技| 黎城县| 石阡县| 常熟市| 葫芦岛市| 青阳县| 上犹县| 无棣县| 玉田县| 栾城县| 栾川县| 甘德县| 布拖县| 凤阳县| 通辽市| 那曲县| 镇江市| 西畴县| 阿鲁科尔沁旗| 崇明县| 牟定县| 贵定县| 东平县| 定西市| 北安市|