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

  • 相关阅读:
    MVC三层架构
    Cookie
    request (请求转发)
    response 重定向
    HttpServletResponse(响应),实现文件下载,实现验证码功能
    HTTP报文格式
    基于UUID生成短ID
    一致性hash应用到redis
    spring-mysqlclient开源了
    Effection Go
  • 原文地址:https://www.cnblogs.com/yongfeiuall/p/4134204.html
Copyright © 2011-2022 走看看