J'ai fait ce petit programme tout simple, qui aurait pu être créé par n'importe quel débutant, car je voulais que lorsque j'archivais certains dossiers en les compressant je puisse ensuite savoir rapidement quels étaient les fichiers du dossier archivé. Ceci dit ça peut surement servir à autre chose.
Source / Exemple :
Public Class GetNames
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyBase.KeyPreview = True
Me.KeyPreview = True
TextBox1.Text = ("Fichiers Archivés (" + CStr(Now.Day) + "-" + CStr(Now.Month) + "-" + CStr(Now.Year) + ")")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Boutonparc1.Click
If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Label2.Text = FolderBrowserDialog1.SelectedPath
Dim i As Integer
i = 0
Dim reader As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
Dim item As String
Dim lastLocation As String
reader = My.Computer.FileSystem.GetFiles(FolderBrowserDialog1.SelectedPath)
While (i < reader.Count)
item = reader.Item(i)
lastLocation = item.LastIndexOf("\")
ListBox1.Items.Add(item.Remove(0, lastLocation + 1))
i = i + 1
End While
End If
End Sub
Dim listeDeFichiers As New ArrayList
Private Sub GetFiles(ByVal repertoire As String)
Dim fichiers As String()
Dim dir As String()
fichiers = IO.Directory.GetFiles(repertoire)
For Each chaine As String In fichiers
listeDeFichiers.Add(chaine)
Next
dir = IO.Directory.GetDirectories(repertoire)
For Each chaine As String In dir
GetFiles(chaine)
Next
End Sub
Private Sub Key_Down(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Delete Then
If ListBox1.Focused = True Then
Dim x As Integer = ListBox1.SelectedIndex
If 0 < x < ListBox1.Items.Count Then
If MsgBox("Voulez-vous vraiment supprimer cet objet?", MsgBoxStyle.OkCancel, "Confirmez") = MsgBoxResult.Ok Then
ListBox1.Items.RemoveAt(x)
End If
Else : MsgBox("Aucun objet selectionné", MsgBoxStyle.OkOnly)
End If
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BoutonSuppr.Click
Dim x As Integer = ListBox1.SelectedIndex
If MsgBox("Voulez-vous vraiment supprimer cet objet?", MsgBoxStyle.OkCancel, "Confirmez") = MsgBoxResult.Ok Then
If 0 < x < ListBox1.Items.Count Then
ListBox1.Items.RemoveAt(x)
End If
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Boutonparc2.Click
If FolderBrowserDialog2.ShowDialog = Windows.Forms.DialogResult.OK Then
Label4.Text = FolderBrowserDialog2.SelectedPath
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BoutonGo.Click
If Label2.Text = " " Then
GoTo 1
End If
If Label4.Text = " " Then
GoTo 1
End If
If TextBox1.Text = "" Then
GoTo 1
End If
Dim FSys As System.Object
FSys = CreateObject("Scripting.FileSystemObject")
Dim MonFic As Object
MonFic = FSys.CreateTextFile(Label4.Text + "\" + TextBox1.Text + ".txt")
Dim nb As Integer = ListBox1.Items.Count
Dim x As Integer = 0
Dim i As Integer = 1
With MonFic
.writeline(TextBox1.Text)
.writeline(" ")
End With
While i < nb
With MonFic
ListBox1.SelectedItem = i
ListBox1.SelectedIndex = i
.writeLine(ListBox1.Text)
ProgressBar1.Value = ((i / nb) * 100)
i = i + 1
End With
End While
MsgBox("Ecriture achevée. En cas de réécriture dans le même dossier pensez à changer de nom ou à supprimer l'ancien fichier", MsgBoxStyle.Information, "Attention!")
ProgressBar1.Value = 0
ListBox1.SelectedIndex = 1
ListBox1.SelectedItem = 1
If MsgBox("Voulez-vous ouvrir le répertoire du fichier créé?", MsgBoxStyle.YesNo, " ") = MsgBoxResult.Yes Then
Shell("C:\WINDOWS\explorer.exe /n, " + FolderBrowserDialog2.SelectedPath)
End If
1:
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Boutonouvrir1.Click
Shell("C:\WINDOWS\explorer.exe /n, " + FolderBrowserDialog1.SelectedPath)
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Boutonouvrir2.Click
Shell("C:\WINDOWS\explorer.exe /n, " + FolderBrowserDialog2.SelectedPath)
End Sub
End Class
Conclusion :
Faites moi part de vos idées pour l'améliorer et si vous voulez le modifier faites-vous plaisir et envoyez-moi vos modifs.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.