Results 1 to 8 of 8

Thread: diretory.getfile("c:\","*.jpg")..more file extension filter

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    diretory.getfile("c:\","*.jpg")..more file extension filter

    i want to get all files *.jpg,*.gif..how can i specify more than 1 extension type??

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: diretory.getfile("c:\","*.jpg")..more file extension filter

    Separate each extension with a semicolon, "*.jpg;*.gif"
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: diretory.getfile("c:\","*.jpg")..more file extension filter

    i already tried this...but it doesn't seem to work

  4. #4
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252

    Re: diretory.getfile("c:\","*.jpg")..more file extension filter

    I find that is a limitation in .NET.

    VB Code:
    1. Dim mFileExt() As String = {"mp3", "m4a"}

    Something similar to this code should do the job.

    VB Code:
    1. For Each fileExt As String In mFileExt
    2.                     'Console.WriteLine("Dir: " & recordPath)
    3.                     For Each filePath As String In Directory.GetFiles(recordPath, "*." & fileExt, SearchOption.AllDirectories)
    4.                         ' Console.WriteLine(filePath)
    5.                         listAddableFiles.Add(filePath)
    6.                     Next
    7.                 Next

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: diretory.getfile("c:\","*.jpg")..more file extension filter

    that's not very practical

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: diretory.getfile("c:\","*.jpg")..more file extension filter

    Perhaps like this

    VB Code:
    1. Dim strExtensions() As String = {".jpg", ".zip"}
    2.         For Each fi As IO.FileInfo In New IO.DirectoryInfo("h:\").GetFiles
    3.             If Not Array.IndexOf(strExtensions, fi.Extension) = -1 Then
    4.                 ' Do what you want
    5.             End If
    6.         Next
    EDIT: But I guess it would be even better to avoid the FileInfo class, as retrieving the files as strings doesnt take as much "resources".
    Last edited by Atheist; Jan 14th, 2007 at 06:35 PM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: diretory.getfile("c:\","*.jpg")..more file extension filter

    VB Code:
    1. Dim folderPath As String = "folder path here"
    2. Dim filePaths As List(Of String)
    3. Dim patterns As String() = {"*.jpeg", "*.jpg"}
    4.  
    5. For Each pattern As String In patterns
    6.     filePaths.AddRange(IO.Directory.GetFiles(folderPath, pattern))
    7. Next pattern
    This code is VB 2005-specific. Please ALWAYS specify your version. In previous versions you'd use a StringCollection instead of a List.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: diretory.getfile("c:\","*.jpg")..more file extension filter

    ok thanks...i guess i will get all files and check if the files are within the extensions i want using getfileinfo.getextension a bit similar to how i was doin in vb6

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