0
For Each File As String In My.Computer.FileSystem.GetFiles(Line, FileIO.SearchOption.SearchTopLevelOnly, "*.txt|*.docx")

Next

is it right to OR extensions this way? I just need to get the txt and docx files

Mark Hall
  • 53,938
  • 9
  • 94
  • 111
Alex
  • 1,639
  • 3
  • 18
  • 33
  • Same as this one http://stackoverflow.com/questions/3527203/getfiles-with-multiple-extentions – Orn Kristjansson Nov 28 '12 at 02:19
  • possible duplicate of [Can you call Directory.GetFiles() with multiple filters?](http://stackoverflow.com/questions/163162/can-you-call-directory-getfiles-with-multiple-filters) – LarsTech Nov 28 '12 at 02:29
  • 2
    Not a duplicate, My.Computer.FileSystem.GetFiles accepts a string array for wildcards – Steve Nov 28 '12 at 07:56

2 Answers2

2

If you look at this MSDN Forum Post it suggests that using an array to hold the file extensions like this will work. Using an Or statement like you have will give you an error.

Dim line As String = "C:\Temp"
Dim extension(1) As String
extension(0) = "*.txt"
extension(1) = "*.docx"

For Each File As String In My.Computer.FileSystem.GetFiles(Line, FileIO.SearchOption.SearchTopLevelOnly, extension)

Next
Mark Hall
  • 53,938
  • 9
  • 94
  • 111
-2
    Dim extension As New List(Of String)
    extension.Add("*.avi")
    extension.Add("*.mkv")
    extension.Add("*.wmv")
    extension.Add("*.mp4")

For Each F In My.Computer.FileSystem.GetFiles("c:\yourPath", FileIO.SearchOption.SearchAllSubDirectories, extension.ToArray)

' do it

next

Yves
  • 1