Posted By

martinbrait on 08/10/19


Tagged

list files directories


Versions (?)

[vba-excel] lister dossiers et sous-dossiers d'un répertoire


 / Published in: Visual Basic
 

URL: list directories subdirectories

How to list directories and subdirectories in an excel sheet ?

  1. Sub TousLesDossiers(LeDossier$, Idx As Long)
  2. Dim strDossier As String
  3. Dim strFichier As String
  4. Dim FSO As Object, Dossier As Object
  5. Dim sousRep As Object, Flder As Object
  6. Set FSO = CreateObject("Scripting.FileSystemObject")
  7. Set Dossier = FSO.GetFolder(LeDossier)
  8.  
  9. 'examen du dossier courant
  10. For Each Flder In Dossier.SubFolders
  11. Idx = Idx + 1
  12. Cells(Idx, 1).Value = Flder.Path & "\"
  13. 'Rajou de fichier #début
  14. ' Lister tous les fichiers du dossier
  15. strFichier = Dir(Flder.Path & "\", vbNormal)
  16. While strFichier <> ""
  17. ' Afficher le nom du fichier
  18. Idx = Idx + 1
  19. Cells(Idx, 1).Value = Flder.Path & "\" & strFichier
  20. 'Lire le fichier suivant
  21. strFichier = Dir
  22. Wend
  23. 'rajout de fichier #fin
  24. Next
  25. 'traitement récursif des sous dossiers
  26. For Each sousRep In Dossier.SubFolders
  27. TousLesDossiers sousRep.Path, Idx
  28. Next sousRep
  29. Set FSO = Nothing
  30. End Sub

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: fayolaa on August 12, 2019

I read your post. It is very informative and helpful to me. I admire the message  valuable information you provided in your article. Thank you for posting, again! [url=https://littlebigsnake.online]little big snake[/url]

You need to login to post a comment.