Alex - 1 year ago 81
Vb.net Question

# VB Read Line from File starting with "XY" and ignore the XY

Im currently working on a program which basicly writes a number of Files and their paths into a file & a new path to be used by another computer to put these files on its hard drive.
I don't know how to read the file properly by the second computer. (The "Receiving part" of the program)

The File which should be read looks like this:

OTHER STUFF
MORE STUFF
EVEN MORE STUFF
File1:~\\bar\foo.txt
Path1:~C:\foo
File2:~\\bar\foobar.txt
Path2:~C:\foobar
OTHER STUFF
MORE STUFF
EVEN MORE STUFF


How Can I read this file and only get the files and paths and exclude the "File" and "Path"?

I'm sorry if my english is not perfect, please ask if something it's not clear.
I hope you can help me.

Regards

This is what i got so far, but it will only display one character after the ~ (I use that as a seperator now)

Dim settings_file As String = "//test/test.txt"
Dim line As String
Do While Not (line Is Nothing)
If line.StartsWith("File") Then
Dim parts As String() = line.Split("~")
For Each part In parts
MsgBox(part(1))
Next
End If
Loop


Dim lines = File.ReadLines("test\test.txt")

Dim paths = From line In lines
Where line Like "File#:~*" OrElse line Like "Path#:~*"
Select Split(line, ":~", 2).Last

Dim result = paths.ToArray


or

Dim lines = File.ReadLines("test\test.txt")

Dim lookup = lines.ToLookup(Function(l) l.Substring(0, 4), Function(l) Split(l, ":~", 2).Last)

Dim files = lookup("File").ToArray
Dim paths = lookup("Path").ToArray

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download