1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
| Imports System.IO
Public Class ListFiles
Public Event RunWorkerCompleted(sender As Object)
Public Event ProgressChanged(sender As Object)
Private mybackgroundWorker1 As System.ComponentModel.BackgroundWorker
Private myNbrFiles As Double = 0
Private myNbrDirectories As Double = 0
Private myMonChemin As String
Private myRichTextBox1 As RichTextBox
Private myNomDossier As String
Private myNomsFichiers As New ArrayList()
' ************************************************************************************************************
' * liste procédures
' ***********************************************************************************************************
Sub New(ByVal MonChemin As String)
myMonChemin = MonChemin
End Sub
Public Sub Start()
AddHandler mybackgroundWorker1.DoWork, AddressOf Me.BackgroundWorker1DoWork
AddHandler mybackgroundWorker1.RunWorkerCompleted, AddressOf Me.BackgroundWorker1RunWorkerCompleted
AddHandler mybackgroundWorker1.ProgressChanged, AddressOf Me.BackgroundWorker1ProgressChanged
myRichTextBox1.Clear
myBackgroundWorker1.RunWorkerAsync(myMonChemin)
End Sub
Public Sub CancelAsync()
mybackgroundWorker1.CancelAsync
End Sub
Private Sub listingSousDossiersRecur(Optional ByVal cheminBranche As String = ".", Optional ByVal objListRep As String() = nothing)
Dim pFichier As String()
Dim cFichiers As String()
'msgbox(cheminBranche)
System.Threading.Thread.Sleep(100)
myNomDossier = cheminBranche
'Application.DoEvents()
pFichier = Directory.GetDirectories(cheminBranche)
cFichiers = Directory.GetFiles(cheminBranche)
myNbrFiles += cFichiers.GetUpperBound(0) + 1
myNbrDirectories += pFichier.GetUpperBound(0) + 1
'Label1.Text = "Nbr Fichiers : " & Ctype(NbrFiles + 1, string)
'Label2.Text = "Nbr Dossiers : " & Ctype(NbrDirectories + 1, string)
'TextBox1.Text = "Nbr Dossiers : " & CType(NbrDirectories + 1, String) & vbcr & _
' "Nbr Fichiers : " & Ctype(NbrFiles + 1, string)
If objListRep is Nothing Then
objListRep = pFichier
End If
myNomsFichiers.Clear
For Each fichier As String in cFichiers
Dim SplitFichier As String()
SplitFichier = fichier.split(CType("\", char))
Dim NomFichier As String = SplitFichier(SplitFichier.GetUpperBound(0))
myNomsFichiers.Add (NomFichier)
Next fichier
'# Listing des sous-dossiers + appel recursif
For Each oSousRep As String In objListRep
Dim objListSousRep As String()
objListSousRep = Directory.GetDirectories(oSousRep)
listingSousDossiersRecur(oSousRep, objListSousRep)
Next
End Sub
Private Sub MAJRichTextBox()
myRichTextBox1.Select(myrichTextBox1.GetFirstCharIndexOfCurrentLine(), 1)
' Mise en Forme du nom du Dossier
Dim currentFont As System.Drawing.Font = myrichTextBox1.SelectionFont
Dim newFontStyle As System.Drawing.FontStyle
'newFontStyle = FontStyle.Bold
newFontStyle = FontStyle.Underline xor FontStyle.Italic
myRichTextBox1.SelectionFont = New Font(currentFont.FontFamily, currentFont.Size, newFontStyle)
'richTextBox1.SelectionFont.b = Color.Red
myRichTextBox1.AppendText(vbcrlf & myNomDossier & vbcrlf)
For Each elm As String in myNomsFichiers
myRichTextBox1.AppendText(elm & vbcrlf)
Next elm
myRichTextBox1.AppendText(vbcrlf)
End Sub
' ************************************************************************************************************
' * liste évenement
' ***********************************************************************************************************
Private Sub BackgroundWorker1DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs)
If mybackgroundWorker1.CancellationPending Then
e.Cancel = True
Exit Sub
End If
listingSousDossiersRecur(e.Argument)
End Sub
Private Sub BackgroundWorker1RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs)
RaiseEvent RunWorkerCompleted(sender)
End Sub
Private Sub BackgroundWorker1ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs)
If Not(myRichTextBox1 Is Nothing) Then
MAJRichTextBox
End If
RaiseEvent ProgressChanged(sender)
End Sub
' ************************************************************************************************************
' * liste propriétés
' ***********************************************************************************************************
Public ReadOnly Property NbrFiles() As Double
Get
Return myNbrFiles
End Get
End Property
Public ReadOnly Property NbrDirectories() As Double
Get
Return myNbrDirectories
End Get
End Property
Public Property RichTextBox() As RichTextBox
Get
Return myRichTextBox1
End Get
Set(ByVal Value As RichTextBox)
myRichTextBox1 = value
End Set
End Property
End Class |
Partager