Windows Forms - File System

Nota : O filesystem é um componente do windows e por esse motivo esta sujeito a segurança do sistema operacional.

Module File_System

Copiar arquivo

    Public Sub CopiarArquivo(origem As String, destino As String)

        If My.Computer.FileSystem.FileExists(destino) Then
            My.Computer.FileSystem.DeleteFile(destino)
        End If
        My.Computer.FileSystem.CopyFile(origem, destino) 'copia mas não sobreescreve
        My.Computer.FileSystem.CopyFile(origem, destino, True) 'true=copia e sobreescreve se já existir

    End Sub

Obter os arquivos da pasta

    Public Sub ObterTodosArquivosdeUmaPasta(pasta As String)
        'varre só a pasta recebida por parametro
        Dim arqs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)

        arqs = My.Computer.FileSystem.GetFiles(pasta, FileIO.SearchOption.SearchTopLevelOnly, "*.*")
    End Sub

    Public Sub ObterTodosArquivosdeUmaPastaComTodosOsSubdiretorios(pasta As String)
        'recebida a pasta recebida por parametro e todas as suas internas
        Dim arqs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)

        arqs = My.Computer.FileSystem.GetFiles(pasta, FileIO.SearchOption.SearchAllSubDirectories, "*.*")
    End Sub

End Module