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 閱讀(883) 評論(0)  編輯  收藏 所屬分類: qtp

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

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 多伦县| 衡东县| 饶平县| 仁布县| 泰安市| 贺兰县| 天台县| 漯河市| 镇江市| 启东市| 石渠县| 秀山| 安阳市| 威海市| 遂昌县| 仪征市| 固阳县| 神池县| 浙江省| 庄河市| 景东| 堆龙德庆县| 杨浦区| 古交市| 昭觉县| 诸暨市| 云霄县| 阿图什市| 沾益县| 福州市| 湛江市| 尉犁县| 萍乡市| 伊吾县| 穆棱市| 竹山县| 临湘市| 彝良县| 越西县| 辰溪县| 彭泽县|