Imports System.IO Private Structure Filedata Public thefilename As String Public thesafefile As String End Structure Private listfilename As New List(Of Filedata) Private Sub Button1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseClick OpenFileDialog1.ShowDialog() End Sub Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk If e.Cancel = True Then Exit Sub Dim thefiledata As New Filedata thefiledata.thefilename = OpenFileDialog1.FileName thefiledata.thesafefile = OpenFileDialog1.SafeFileName If Not listfilename.Contains(thefiledata) Then listfilename.Add(thefiledata) End If End Sub Private Sub CopyFile(ByVal destpath As String) For Each item In listfilename If Directory.Exists(destpath) Then File.Copy(item.thefilename, destpath & item.thesafefile) 'veux tu effacer le fichier ? File.Delete(item.thefilename) End If Next listfilename.clear End Sub Private Sub Button2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseClick CopyFile("C:\TEST") End Sub
Imports System.IO Private Structure Filedata Public thefilename As String Public thesafefile As String Public flagdel As Boolean End Structure Private listfilename As New List(Of Filedata) Private Sub Button2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseClick Dim thefiledata As New Filedata Dim iter As Integer For Each item In ListBox1.SelectedItems For iter = 0 To listfilename.Count - 1 If item.ToString = listfilename(iter).thefilename Then thefiledata.flagdel = True thefiledata.thefilename = listfilename(iter).thefilename thefiledata.thesafefile = listfilename(iter).thesafefile listfilename.Remove(listfilename(iter)) listfilename.Insert(iter, thefiledata) Exit For End If Next Next CopyFile("C:\TEST") End Sub Private Sub Button1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseClick OpenFileDialog1.ShowDialog() End Sub Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk If e.Cancel = True Then Exit Sub Dim thefiledata As New Filedata Dim iter As Integer For iter = 0 To OpenFileDialog1.FileNames.Length - 1 thefiledata.thefilename = OpenFileDialog1.FileNames(iter) thefiledata.thesafefile = OpenFileDialog1.SafeFileNames(iter) thefiledata.flagdel = False If Not listfilename.Contains(thefiledata) Then listfilename.Add(thefiledata) ListBox1.Items.Add(thefiledata.thefilename) End If Next End Sub Private Sub CopyFile(ByVal destpath As String) If Directory.Exists(destpath) Then For iter = 0 To listfilename.Count - 1 If listfilename(iter).flagdel Then File.Copy(listfilename(iter).thefilename, destpath & listfilename(iter).thesafefile) File.Delete(item.thefilename) End If Next For iter = listfilename.Count - 1 To 0 Step -1 If listfilename(iter).flagdel Then ListBox1.Items.RemoveAt(iter) listfilename.RemoveAt(iter) End If Next End If End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk If e.Cancel = True Then Exit Sub Dim thefiledata As New Filedata Dim iter As Integer For iter = 0 To OpenFileDialog1.FileNames.Length - 1 thefiledata.thefilename = OpenFileDialog1.FileNames(iter) thefiledata.thesafefile = OpenFileDialog1.SafeFileNames(iter) If Not listfilename.Contains(thefiledata) Then listfilename.Add(thefiledata) End If Next End Sub
File.Delete(listfilename(iter).thefilename)
PictureBox c'est juste par soucis d'esthétisme