VBS解压zip文件并且递归统计文件数目

来源:互联网 发布:膳魔师淘宝旗舰店 编辑:程序博客网 时间:2024/05/01 12:13

'解压zip文件到myTargetDir

Sub UnZip(ByVal myZipFile, ByVal myTargetDir)

    Set fso = CreateObject("Scripting.FileSystemObject")
    If NOT fso.FileExists(myZipFile) Then
        Exit Sub
    ElseIf fso.GetExtensionName(myZipFile) <> "zip" Then
        Exit Sub
    ElseIf NOT fso.FolderExists(myTargetDir) Then
        fso.CreateFolder(myTargetDir)
    End If
    Set objShell = CreateObject("Shell.Application")
    Set objSource = objShell.NameSpace(myZipFile)
    Set objFolderItem = objSource.Items()
    Set objTarget = objShell.NameSpace(myTargetDir)
    intOptions = 256
    objTarget.CopyHere objFolderItem, intOptions

End Sub

UnZip "E:\Log\1.zip", "E:\log"


'递归统计文件数目

Function allfilescount(rootpath)
Set fso = CreateObject("Scripting.FileSystemObject")
set fol = fso.GetFolder(rootpath)
dim temp : temp = fol.Files.Count

If fol.SubFolders.Count>0 Then
Set sf = fol.SubFolders
For each fa in sf
dim foldpath
foldpath = rootpath &"\"&fa.name
Set fol = fso.GetFolder(foldpath)
temp = temp + fol.Files.Count
Next
End If
allfilescount = temp
End Function


msgbox allfilescount("e:\log\翻墙软件")

原创粉丝点击