Results 1 to 2 of 2

Thread: Recursive serach

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    32

    Recursive serach

    How can i search recursive through directories for files with a specified extention ?

  2. #2
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    Well you would start with a root directory and pass it to a procedure:-

    'some example prohibitive string variables
    dim PrivateFiles as string
    dim AllowedExtensions as string
    dim PrivateFolders as string

    'these strings are for readability comma delimited with
    'specific extensions, files, folders etc.
    'you could have a privateextensions string too
    'e.g.
    AllowedExtensions = ".txt,.doc,.asp,.aspx"
    PrivateFiles = "private.dll,private.doc,private.asp"
    PrivateFolder = "bin,windows,private"

    dim Files as new arraylist

    GetAllFiles("c:")

    Sub GetAllFiles(ByVal RootFolder as string)
    dim FileName as string
    for each FileName in System.IO.Directory.GetFiles(RootFolder)
    dim FInfo as new System.IO.FileInfo(FileName)
    if AllowedExtensions.IndexOf("." & FInfo.Extension) > -1 and PrivateFiles.IndexOf(FileName.SubString(FileName.LastIndexOf("\"))+1) = -1
    'this file and extension is allowed in our search
    Files.Add(FileName)
    end if
    next
    dim FolderName as string
    for each FolderName in System.IO.Directory.GetDirectories(RootFolder)
    dim FldrInfo as new System.IO.DirectoryInfo(FolderName)
    If PrivateFolder.IndexOf(FldrInfo.Name) = -1
    'folder is allowed - do recursive search
    GetAllFiles(FolderName)
    end if
    next
    end sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width