zoukankan      html  css  js  c++  java
  • [唐胡璐]VBS技巧 Find a File Recursively(递归查找文件)

       '-----------------------------------------------------------------------
      'Function: FindFileRecursively
      'Finds the first instance of a file within the root folder or one of its subfolders
      '
      'Remarks:
      '   Uses recursion
      '
      'Arguments
      '   ByVal strRootFolder - As String (absolute folder)
      '   ByVal strFilename - As String
      '
      'Returns:
      '   String with full file pathname based on root folder and file name
      '
      'Owner:
      '
      'Date:
      '
      '-----------------------------------------------------------------------    
       PublicFunction FindFileRecursively(ByVal strRootFolder, ByVal strFilename)
          Dim FSO    
          Dim strFullPathToSearch    
          Dim objSubFolders, subfolder    
       
          Set FSO = CreateObject("Scripting.FileSystemObject")    
          'Initialize function    
          FindFileRecursively = ""    
          'Check that filename is not empty    
          If strFileName = ""ThenExitFunction    
          'Get full file pathname    
          strFullPathToSearch = strRootFolder & "\" & strFilename    
          'Check if root folder exists    
          If FSO.FolderExists(strRootFolder) Then        
              'Check if file exists under root folder        
              If FSO.FileExists(strFullPathToSearch) Then            
                  FindFileRecursively = strFullPathToSearch        
              Else            
                  'Get subfolders            
                  Set objSubFolders = FSO.GetFolder(strRootFolder).SubFolders            
                  ForEach subfolderin objSubFolders                
                      strFullPathToSearch = strRootFolder & "\" & subfolder.name                
                      FindFileRecursively = FindFileRecursively(strFullPathToSearch, strFilename)                
                      If FindFileRecursively <> ""Then                    
                          ExitFor                
                      EndIf            
                  Next        
              EndIf    
          EndIf
      EndFunction

  • 相关阅读:
    Ubuntu+Windows双系统升级Windows启动项消失恢复
    day19 Servlet Filter
    day17 dbutils 和 jdbc 多表操作
    day16 事务
    day15 分页及 JDBC 大数据的处理
    day14 JDBC
    day13 MySQL 及数据库相关
    Windows系统中完全卸载MySQL数据库,实现重装
    Elasticsearch 6.5.4 安装IK Analysis插件
    js 常用功能
  • 原文地址:https://www.cnblogs.com/yongfeiuall/p/4134204.html
Copyright © 2011-2022 走看看