我有以下文本文件,其中包含需要检查是否存在的文件路径:
C:\path\to\file1
C:\path\to\file2
C:\path\to\file3
C:\path\to\file4
我已经尝试编写一些vb(第一次)来逐行读取所述文本文件,存储该行,并检查该字符串是否存在。代码如下:
Imports System.IO
Module Module1
Sub Main()
' Store the line in this String.
Dim line As String
' Create new StreamReader instance with Using block.
Using reader As StreamReader = New StreamReader("file.txt")
' Read one line from file
line = reader.ReadLine
End Using
' Write if the file exists or not
Console.WriteLine(File.Exists(line) ? "File exists." : "File does not exist.");
End Sub
我的问题是,假设我想给文件添加一个远程路径,我需要在上面的代码中更改什么才能检查它?
即
C:\path\to\file1
C:\path\to\file2
C:\path\to\file3
C:\path\to\file4
\\server.domain\path\to\file5
\\server.domain2\path\to\file6
提前谢谢你。
注释后更正:
Imports System.IO
Module Module1
Sub Main()
' Loop over lines in file.
For Each line As String In File.ReadLines("file.txt")
' Display the line.
Console.WriteLine(File.Exists(line) ? "File exists." : "File does not exist.");
Next
End Sub
End Module