[原创]qtp用Vbscript进行文件对象…

本帖子为本人原创,转载请注明作者:Cheers Li 以及网络来源:

 

1.QTP 调用 xstadard 对文件/文件夹打包 实例

 

QTP 脚本如下:

Dim objZip
set objZip=createobject("XStandard.Zip")

objZip.Pack "C:\Temp\original","C:\Temp\zip\zipbmp01.zip",True,"CheersLi测试"
Set objZip=nothing

 

更多参考: http://hi.baidu.com/xuyanbin/blog/item/de96a63eea224fff828b130f.html

 

2.qtp用Vbscript进行文件对象操作脚本总结

大概总结了下,格式也不想再改了.不用的地方可以注释掉.

 Set fso=createobject("Scripting.FileSystemObject")
      '===================获取文件夹文件数量和文件名,并打印出来=================
    set f= fso.getfolder("D:\temp\qtp")
    Dim n
    For each x in f.files
  'msgbox x.name
  a=a&x.name&vbcrlf
  n=n+1
    Next
 Print  "共有:"&n&"文件,分别为:"&vbcrlf &a
         '===================获取文件夹文件数量和文件名,并打印出来=================

      '===================创建文件夹并判断实例=================
     
      If (fso.folderexists("D:\temp\qtp\temp")) Then
'        msgbox "File createfile01.txt is exsit,要删除吗 ?",65,"文件提示信息"
       a=msgbox ( "文件夹 ""temp"" 已经存在,要删除吗 ?",65,"文件夹操作提示信息")
'       msgbox a
           If a=1 Then
             fso.deletefolder("D:\temp\qtp\temp")
           End If
       else
        fso.createfolder("D:\temp\qtp\temp")
      msgbox "文件夹temp创建成功!",65,"文件夹操作提示信息"
      End If
    Set fso=nothing
   
      '===================创建文件夹并判断实例=================
   
     '===================读取文件内容=================
     
 Set openfile=fso.opentextfile("D:\temp\qtp\details.doc",1)
 contents=openfile.readall
 print  contents
 
       
     '=================== 按行读取=================
     
  Set openfile=fso.opentextfile("D:\temp\qtp\details.txt",1)
    Do  until openfile.AtEndOfStream
  strline=openfile.readline
 ' msgbox strline
  a=a&strline&vbcrlf
    Loop
    print a
      '===================读取文件内容=================

 
      '===================创建文件并判断实例=================
     
       If (fso.fileexists("D:\temp\qtp\Newfile.txt")) Then
 '        msgbox "File createfile01.txt is exsit,要删除吗 ?",65,"文件提示信息"
        a=msgbox ( "File ""Newfile.txt"" 已经存在,要删除吗 ?",65,"文件提示信息")
 '       msgbox a
            If a=1 Then
              fso.deletefile("D:\temp\qtp\Newfile.txt")
            End If
        else
         fso.createtextfile("D:\temp\qtp\Newfile.txt")
       msgbox "文件创建成功!",65,"文件创建提示信息"
       End If
     Set fso=nothing
   
      '===================创建文件并判断实例=================

你可能感兴趣的:([原创]qtp用Vbscript进行文件对象…)