⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compress.vbs

📁 Apress - Managing Enterprise Systems With The Windows Script Host Source Code
💻 VBS
字号:
'compress.vbs
Option Explicit

Dim objFSO, strWMIPath, objService, objFolders, objFolder, objWMIObject

'create a FSO object
Set objFSO = CreateObject("Scripting.FileSystemObject")

'get a reference to a WMI service on the local machine
Set objService = _
    GetObject("winmgmts:{impersonationLevel=impersonate}!root\cimv2")

'get the folder to search
Set objFolders = objFSO.GetFolder("D:\cc")

'loop through each folder
For Each objFolder In objFolders.SubFolders

    'if folder over certain size, then compress
    If objFolder.Size > 25000000 Then

     'get a reference to the directory to compress
      Set objWMIObject = _
        objService.Get("Win32_Directory.Name=" & chr(34) & _
            Replace(objFolder.Path,"\","\\") & chr(34))
    
      'invoke Compress method
      objWMIObject.Compress
    
    Wscript.Echo "Compressed folder " & objFolder.Path
    
    End If

Next

'release resources
Set objWMIObject = Nothing
Set objFSO = Nothing
Set objFolder = Nothing
Set objService = Nothing

'\\ANARCHY\root\CIMV2:CIM_DataFile.Name="C:\\WINDOWS\\COMMAND\\EXTRACT.EXE"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -