Gopal
Gopal

Reputation: 11972

How to search a file in the folder

Using VB.Net & Window application

I want to get a list of file from the folder

File name like = FTSDD06???035????????????.FTR

Tried Code

Public Function GetFileNames(ByVal sFolder As String, ByVal sFileNamePattern As String, _
            ByVal iMaxFiles As Integer) As List(Of String)
        Return GetFileNames(sFolder, sFileNamePattern, iMaxFiles, False) 'False=include empty files
    End Function

Above code is not working, not getting anything

I want to get all the files from the folder where filename contain **FTSDD06???035????????????.FTR*

Need code help

Upvotes: 0

Views: 77

Answers (2)

You might want to make certain you are calling the NET method to get files as in Directory.GetFiles rather than a local method of the same name. At a minimum it should make the code less confusing; without looking carefully, it looks like it should be recursing.

Dim files = Directory.GetFiles("C:\Temp", "c???_???_??x_???.jpg",
          SearchOption.TopDirectoryOnly)

This works for me to find the one and only file which matches that pattern.

Upvotes: 1

Omar AlMA3lOl
Omar AlMA3lOl

Reputation: 278

this code will help you to get Files and will teach you some-how to use "List(Of Type)" :

    Dim Files_With_Same_Name As New List(Of String)
    For Each file_with_Name In IO.Directory.GetFiles("Your Path", "", IO.SearchOption.TopDirectoryOnly)
        If file_with_Name.Contains("FTSDD06") And file_with_Name.Contains("035") And file_with_Name.Contains(".FTR") Then
            Files_With_Same_Name.Add(file_with_Name)
        End If
    Next
    Dim Files() As String = Files_With_Same_Name.ToArray

NOTE : the IF condition in this case is used to find any file with the parts of name given .

Upvotes: 0

Related Questions