zoukankan      html  css  js  c++  java
  • 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. 递归遍历文件夹

  • 相关阅读:
    <style>的scope属性
    scrollIntoView的使用
    需要学习的内容列表
    react生命周期
    JS对象-不可扩展对象、密封对象、冻结对象
    神策埋点
    Django初识
    MySQL的sql_mode模式说明及设置
    MySQL的逻辑查询语句的执行顺序
    MySQL行(记录)的详细操作
  • 原文地址:https://www.cnblogs.com/Tcorner/p/1774802.html
Copyright © 2011-2022 走看看