parsing strings during objReader.ReadLine

tommyt11

Member
Joined
Dec 21, 2015
Messages
23
Location
Columbus, Ohio
Programming Experience
5-10
I'm having difficulty finding exactly what I need.
I have code that gets Initial Path, Return Path and a List of FileNames with FullPath of filename
All works well, but in the list of filenames I need to trim or split the filenames to only have filename with extensions(no path)
I'm trying to do this as the object is created but cannot find anything to do this during the read line process.
Here is my code:
    Function MyFunction()
        On Error Resume Next
        Dim appData As String = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
        Dim mfnames As String = ""
        Dim f As Integer
        Dim mflines As System.IO.StreamReader

        mflines = My.Computer.FileSystem.OpenTextFileReader(appData & "myfile.txt")

        If System.IO.File.Exists(appData & "myfile.txt") = True Then

            Dim objReader As New System.IO.StreamReader(appData & "myfile.txt")

            Do While objReader.Peek() <> -1

                mfnames = mfnames & objReader.ReadLine() & vbNewLine        

'This returns me a line by line list such as D:/folder/subfolder/filename.ext but I would like it to trim to just (filename.ext). Note some paths may have different depths so I would like to trim from Last instance of char("/")

            Loop

            MsgBox(mfnames)

        Else

            MessageBox.Show("File Does Not Exist")

        End If

    End Function

Not even sure if this is possible but would like to try if it is.
 
You don't do anything "during the ReadLine process". That ReadLine method reads a line from the file and returns it as a String. That's it, that's all. What you then do with that String is completely up to you and completely unconnected to the ReadLine call.

As for the issue, the System.IO.Path class has methods for manipulating file and folder paths, including one that will get a file name without path or extension.
 

Latest posts

Back
Top