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)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 沭阳县| 故城县| 寿光市| 易门县| 丘北县| 西丰县| 汨罗市| 杭锦后旗| 海口市| 平顺县| 法库县| 穆棱市| 盖州市| 黑山县| 台东市| 襄汾县| 阿合奇县| 从化市| 睢宁县| 高邑县| 景宁| 宝兴县| 德清县| 华安县| 扎鲁特旗| 德昌县| 通辽市| 柞水县| 方城县| 新疆| 岳阳县| 农安县| 冷水江市| 南投市| 苏州市| 许昌县| 洪雅县| 安龙县| 黔西县| 临潭县| 宜兰县|