我的csdn博客地址: http://blog.csdn.net/blizzardlyk

使用QTP与Winrar,压缩指定的文件

上一篇 / 下一篇  2010-08-25 10:31:15 / 个人分类:QTP

利用QTP中SystemUtil.Run的功能,将指定文件压缩成RAR格式。

代码如下:
'定义压缩文件的函数,参数包括源文件和目标文件

Function CompressFile(soursefile,targetfile)  
    On error resume next  
    CompressFile = false  
    m1 = chr(34) &targetfile& chr(34)  
    m2 = chr(34) & soursefile& chr(34)  
    command = "a -EP" & " " & m1 & " " & m2  
    SystemUtil.Run "winrar.exe",command  
    Set fso = CreateObject("Scripting.FileSystemObject")  
    For i = 0 to 15  
        If  not fso.FileExists(targetfile) Then 
            wait(2)       
        else  
            CompressFile = True 
            Exit for   
        End If 
    Next      
    Set fso = Nothing 
End Function 

'调用压缩函数,压缩指定文件 
CompressFile "c:\attachment.txt","c:\attachment.rar"

 


TAG: 压缩文件 QTP

 

评分:0

我来说两句

Open Toolbar