Eu tenho o seguinte arquivo de texto contendo caminhos de arquivos que eu preciso verificar a existência de:
C:pathtofile1
C:pathtofile2
C:pathtofile3
C:pathtofile4
Tentei escrever um pouco de vb (pela primeira vez) para ler o arquivo de texto, linha por linha, armazenar a linha e verificar a existência dessa string. Aqui está o código:
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
Minha pergunta é: digamos que eu desejasse adicionar um caminho remoto ao arquivo, o que eu precisaria alterar no código acima para poder verificar isso?
ou seja
C:pathtofile1
C:pathtofile2
C:pathtofile3
C:pathtofile4
\server.domainpathtofile5
\server.domain2pathtofile6
Agradeço antecipadamente.
Correção após comentário:
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
Respostas:
1 para resposta № 1Os caminhos de rede geralmente são assim: //192.168.x.y/Users/
depois de Usuários, você coloca o caminho do arquivo.
192.168.x.y é o endereço IP da máquina remota. Você também pode usar o nome do host no lugar do endereço IP.
Eu espero que isso ajude.