QTP通过Winrar或者纯VBS代码压缩指定的文件或文件夹
2010-08-24 18:37
531 查看
1,利用QTP中SystemUtil.Run的功能,将指定文件压缩成RAR格式。
代码如下:
2,利用VBS:'Zip File or folder 'Example:Zip "C:\temp", "C:\Temp.zip"
代码如下:
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"
2,利用VBS:'Zip File or folder 'Example:Zip "C:\temp", "C:\Temp.zip"
Function ZipFile(ByVal mySourceDir, ByVal myZipFile) Set fso = CreateObject("Scripting.FileSystemObject") If fso.GetExtensionName(myZipFile) <> "zip" Then Exit Sub ElseIf fso.FolderExists(mySourceDir) Then FType = "Folder" ElseIf fso.FileExists(mySourceDir) Then FType = "File" FileName = fso.GetFileName(mySourceDir) FolderPath = Left(mySourceDir, Len(mySourceDir) - Len(FileName)) Else Exit Sub End If Set f = fso.CreateTextFile(myZipFile, True) f.Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0)) f.Close Set objShell = CreateObject("Shell.Application") Select Case Ftype Case "Folder" Set objSource = objShell.NameSpace(mySourceDir) Set objFolderItem = objSource.Items() Case "File" Set objSource = objShell.NameSpace(FolderPath) Set objFolderItem = objSource.ParseName(FileName) End Select Set objTarget = objShell.NameSpace(myZipFile) intOptions = 256 objTarget.CopyHere objFolderItem, intOptions Do wait 1 Loop Until objTarget.Items.Count > 0 End Function
相关文章推荐
- java批量修改指定文件夹下所有后缀名的文件为另外后缀名的代码
- 通过vbs获取远程host文件并保存到指定目录
- Git如何Check Out出指定文件或者文件夹
- Java代码压缩文件夹及多文件压缩---简单案例
- win32命令行小程序获取指定文件夹或者目录下面的所有文件大小,文件数量,目录数量
- 利用WinRAR命令行压缩文件或文件夹2007-11-14 15:07压缩文件夹
- Java将指定文件/文件夹压缩成zip、rar压缩文件
- 通过递归查询指定目录下的所有文件和子文件夹下的指定文件名
- [C#常用代码]如何把指定文件夹中的文件移动到指定的文件夹
- asp.net 删除文件夹内的所有文件 或者单个文件 代码
- C#/ASP.NET/WinForm 通过ICSharpCode.SharpZipLib.dll实现文件夹、文件的压缩与解压
- C#打开指定文件夹及下载文件代码示例
- C# 利用WinRAR (加密)压缩及解压缩 相关文件夹及文件
- java——压缩文件或者文件夹
- 读取指定文件夹下的全部文件,可通过正则进行过滤,返回文件路径数组 -- 基于node的一个函数
- iis 6.0限制通过域名或者ip的形式从外部访问.txt的文件( IIS6.0禁止用户下载指定类型文件)
- 批量修改指定文件夹下所有后缀名的文件为另外后缀名的java代码
- C# 利用WinRAR (加密)压缩及解压缩 相关文件夹及文件
- 通过ZipOutputStream压缩文件夹中的文件