• VBS Example: 如何搜索文件夹中特定类型的文件,并输出到log文件


    问题描述:利用VBS遍历某一个文件路径下,所有后缀名为DLL的文件,并将所有搜索得到的文件路径放到一个Log文件中。

    VBS代码如下:

    Option Explicit
    
    Dim oFSO, oFolder,oSubFolders, oSubFolder, oFiles, oFile
    
    Dim OutputLog,strPathName
    
    strPathName = "D:\"
    
    TranverseFile(strPathName)
    
    Function TranverseFile(strPathName)
    
    	Set oFSO = CreateObject("scripting.filesystemobject")
    
    	Set oFolder = oFSO.GetFolder(strPathName)
    
    	Set oFiles = oFolder.Files
    
    	
    
    	'Tranverse every file in the specified file path and 
    
    	'record the file path to the log.txt file.
    
    	For Each oFile In oFiles
    
    		If StrComp(LCase(oFSO.GetExtensionName(oFile)),"dll")=0 Then
    
    			If(oFSO.FileExists("D:\log.txt")) Then
    
    				Set OutputLog = oFSO.OpenTextFile("D:\log.txt",8,False )
    
    				OutputLog.WriteLine oFile.Path
    
    				OutputLog.Close
    
    			Else
    
    				Set OutputLog = oFSO.OpenTextFile("D:\log.txt",2,True)
    
    				OutputLog.WriteLine oFile.Path
    
    				OutputLog.Close
    
    			End If 
    
    		End If 
    
    	Next
    
    	
    
    	Set oSubFolders = oFolder.subfolders
    
    	
    
    	'Recurse the subFolder
    
    	For Each oSubFolder In oSubFolders
    
    		TranverseFile(oSubFolder)
    
    	Next 
    
    	
    
    	Set oFSO = Nothing
    
    	Set oFolder = Nothing 
    
    	Set oSubFolders = Nothing 
    
    	Set oSubFolder = Nothing 
    
    	Set oFiles = Nothing 
    
    	Set oFile = Nothing 
    
    End Function

    在这里主要覆盖以下的知识点:

    1. 文件的读写

    2. 递归遍历文件夹

  • 相关阅读:
    JQ之html,text,val
    JQuery之编写弹窗
    DOM操作HTML元素属性
    DOM操作表格
    无缝滚动效果
    Date日期基础
    CISSP备考总结
    CISA考试大纲即将更新
    备考CISSP
    cisa备考体会
  • 原文地址:https://www.cnblogs.com/Tcorner/p/1774802.html
Copyright © 2020-2023  润新知