Copier fichiers sur une clé usb

Résolu
huggo1 Messages postés 3 Date d'inscription samedi 4 octobre 2014 Statut Membre Dernière intervention 10 mai 2015 - 10 mai 2015 à 19:49
huggo1 Messages postés 3 Date d'inscription samedi 4 octobre 2014 Statut Membre Dernière intervention 10 mai 2015 - 10 mai 2015 à 20:16
Bonjour,

Je souhaite copier des fichiers texte qui se trouvent dans un dossier vers une clé USB.
Je me perds un peu dans toutes ces lignes.
Un petit coup de main serait le bienvenue.
Merci d'avance.

Dim path1 As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Backup Of Files\" 
Dim theFiles() As String = System.IO.Directory.GetFiles(path1, FileIO.SearchOption.SearchAllSubDirectories, "*.txt")
        For Each currentFile As String In theFiles
            Try
                For Each drive As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives
                    If drive.DriveType = IO.DriveType.Removable AndAlso drive.IsReady Then

                        Dim DriveLetter As String = drive.Name
                        Dim PathToUSBDrive = DriveLetter & IO.Path.GetFileName(currentFile)
                        My.Computer.FileSystem.CopyFile(currentFile, PathToUSBDrive, True)
                                
                   End If
                Next
            Catch ex As Exception
            End Try
        Next

1 réponse

huggo1 Messages postés 3 Date d'inscription samedi 4 octobre 2014 Statut Membre Dernière intervention 10 mai 2015
Modifié par huggo1 le 10/05/2015 à 20:16
Cool j'ai trouvé mon erreur!!!

Pour ce que sa peut aider.

Dim MyDoc As New IO.FileInfo(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Backup Of Files\test\")

        For Each foundFile As String In My.Computer.FileSystem.GetFiles(MyDoc.Directory.FullName, FileIO.SearchOption.SearchAllSubDirectories, "*.txt")

            Try
                For Each drive As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives
                    If drive.DriveType = IO.DriveType.Removable AndAlso drive.IsReady Then ' AndAlso drive.AvailableFreeSpace >= 2 * Gig Then

                        Dim DriveLetter As String = drive.Name
                        Dim PathToUSBDrive = DriveLetter & IO.Path.GetFileName(foundFile)

                        My.Computer.FileSystem.CopyFile(foundFile, PathToUSBDrive, True)

                    End If
                Next
            Catch ex As Exception
            End Try
        Next
0
Rejoignez-nous