mercredi 30 octobre 2013

Copier un fichier en visual basic

Copier un fichier en visual basic

FileCopy est la méthode la plus simple pour copier un fichier sous Windows à l’aide de Visual Basic ou VB. La fonction ne possède que 2 arguments:


        'calling the FileCopy method, very simple
        FileCopy(Source, Destination)



J’ai fabriqué un exemple à télécharger qu’on peut aussi voir ci-dessous. J’ai ajouté 2 fenêtres pour obtenir plus facilement les noms des fichiers sources et destinations. SAmpleCopyFile.zip



''' <summary>
''' This is a sample
''' This show you how to use FileCopy method to copy a file
''' There are better way to copy a file other than FileCopy
'''
''' This is very basic, there is no checking, no security, no rights.
''' Use copy file for simple task or basic operations.
''' </summary>
''' <remarks></remarks>
Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Dim Source As String = ""
        Dim Destination As String = ""

        'get a file name
        Using oOpenFileDialog As New OpenFileDialog
            If oOpenFileDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Source = oOpenFileDialog.FileName
            End If
        End Using

        'Get the name to save to
        Using oSave As New SaveFileDialog
            If oSave.ShowDialog = Windows.Forms.DialogResult.OK Then
                Destination = oSave.FileName
            End If
        End Using

        'calling the FileCopy method, very simple
        FileCopy(Source, Destination)

        Me.Close() 'close the form because the sample is completed.

    End Sub
End Class







This email is free from viruses and malware because avast! Antivirus protection is active.

Aucun commentaire:

Enregistrer un commentaire