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

  • 相关阅读:
    docker镜像制作及上传到远端镜像仓库
    mysql索引进阶
    电子商务需要用到香港服务器吗?
    golang module goland 配置代理
    nginx做linux服务时,日志有权限提示没权限(nginx: [emerg] open() "/home/www/log/error.log" failed)
    Yaml 、Json 、Dict 之间的转化
    CodeSmith .NET三层架构模板
    C#获取26个英文字母
    基于PCASClass.js和layui.js的城市三级联动
    MySQL变量的使用
  • 原文地址:https://www.cnblogs.com/yongfeiuall/p/4134204.html
Copyright © 2011-2022 走看看