Sub TousLesDossiers(LeDossier$, Idx As Long) Dim fso As Object, Dossier As Object Dim sousRep As Object, Flder As Object Set fso = CreateObject("Scripting.FileSystemObject") Set Dossier = fso.GetFolder(LeDossier) 'examen du dossier courant For Each Flder In Dossier.subfolders Idx = Idx + 1 Cells(Idx, 1).Value = Flder.Path Next 'traitement récursif des sous dossiers For Each sousRep In Dossier.subfolders TousLesDossiers sousRep.Path, Idx Next sousRep Set fso = Nothing End Sub 'fs 'utilisation Sub test() TousLesDossiers "C:\Documents and Settings", 0 End Sub
For Each Flder In Dossier.subfolders Idx = Idx + 1 If "dossier cherché" = Flder.Path Then MsgBox "dossier existe dans " & Flder.Path Exit Sub End If Next
Imports System.IO Private Function DirectoryExist(ByVal dirName As String, ByVal dirPath As String) As String If Directory.Exists(Path.Combine(dirPath, dirName)) Then Return dirPath Else For Each subDirPath As String In Directory.GetDirectories(dirPath) If Not String.IsNullOrEmpty(DirectoryExist(dirName, subDirPath)) Then Return subDirPath End If Next End If Return String.Empty End Function
Dim dirToFind As String = "Dossier4" Dim res As String = DirectoryExist(dirToFind, "C:\Dossier1") If Not String.IsNullOrEmpty(res) Then MessageBox.Show(String.Format("Le dossier {0} existe dans le dossier {1}", dirToFind, res)) End If
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questiongoogle est mon ami quand tu cherches quelque chose demande lui clairement