Accueil > > > LISTER TOUS LES FICHIERS D'UN DOSSIER ET DE SES SOUS-DOSSIERS
LISTER TOUS LES FICHIERS D'UN DOSSIER ET DE SES SOUS-DOSSIERS
Information sur la source
Description
Lister tous les fichiers d'un dossier et de ses sous-dossiers source net
Source
- Attribute VB_Name = "ListeFichiersEtDossiers"
-
-
- Option Explicit
-
- '32-bit API declarations
-
- Declare Function SHGetPathFromIDList Lib "shell32.dll" _
- Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
-
- Declare Function SHBrowseForFolder Lib "shell32.dll" _
- Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
-
- Public Type BROWSEINFO
- hOwner As Long
- pidlRoot As Long
- pszDisplayName As String
- lpszTitle As String
- ulFlags As Long
- lpfn As Long
- lParam As Long
- iImage As Long
- End Type
-
-
- Sub ListFiles()
-
- Dim msg As String, answer As String
- Dim Directory As String
- Dim R As Integer
- Dim i As Integer
- Dim StartDate As Single
-
-
- msg = "Select a location containing the files you want to list."
- Directory = GetDirectory(msg)
- If Directory = "" Then Exit Sub
- If Right(Directory, 1) <> "\" Then Directory = Directory & "\"
-
- ' Insert headers
-
- R = ActiveCell.Row
- Cells(R, 1) = "FilePath"
- Cells(R, 2) = "Size"
- Cells(R, 3) = "Date/Time"
- Cells(R, 4) = "Filename"
- Range("A1:C1").Font.Bold = True
- R = R + 1
-
- On Error Resume Next
- With Application.FileSearch
- .NewSearch
- .LookIn = Directory
- .Filename = "*.*" ' this can be '*.*
- .SearchSubFolders = True
- .Execute
- For i = 1 To .FoundFiles.Count
- If FileDateTime(.FoundFiles(i)) > StartDate Then
- Cells(R, 1) = .FoundFiles(i)
- Cells(R, 4) = Right(Cells(R, 1), Len(.FoundFiles(i)) - InStrRev(Cells(R, 1).Value, "\"))
- Cells(R, 2) = FileLen(.FoundFiles(i))
- Cells(R, 3) = FileDateTime(.FoundFiles(i))
- R = R + 1
- End If
- Next i
- End With
- 'Columns("A:C").Select
- 'Selection.Columns.AutoFit
-
- 'ActiveSheet.Columns("1:3").AutoFit
- MsgBox "file listing complete"
-
- End Sub
-
- Function GetDirectory(Optional msg) As String
- Dim bInfo As BROWSEINFO
- Dim path As String
- Dim R As Long, x As Long, pos As Integer
-
- ' Root folder = Desktop
- bInfo.pidlRoot = 0&
-
- ' Title in the dialog
- If IsMissing(msg) Then
- bInfo.lpszTitle = "Select a folder"
- Else
- bInfo.lpszTitle = msg
- End If
-
- ' Type of directory to return
- bInfo.ulFlags = &H1
-
- ' Display the dialog
- x = SHBrowseForFolder(bInfo)
-
- ' Parse the result
- path = Space$(512)
- R = SHGetPathFromIDList(ByVal x, ByVal path)
- If R Then
- pos = InStr(path, Chr$(0))
- GetDirectory = Left(path, pos - 1)
- Else
- GetDirectory = ""
- End If
- End Function
-
- Function InStrLast(iStart As Integer, szSrchIn As String, _
- szSrchFor As String, iCompare As Integer) As Integer
- Dim iPrevFoundAt As Integer
- Dim iFoundAt As Integer
- On Error GoTo ErrExit_InStrLast
- iPrevFoundAt = 0
- iFoundAt = InStr(iStart, szSrchIn, szSrchFor, iCompare)
- Do While iFoundAt > 0
- iPrevFoundAt = iFoundAt
- iFoundAt = InStr(iPrevFoundAt + 1, szSrchIn, szSrchFor, iCompare)
- Loop
- ErrExit_InStrLast:
- If Err <> 0 Then MsgBox Error$, vbExclamation
- InStrLast = iPrevFoundAt
- Exit Function
- End Function
-
-
-
-
-
Attribute VB_Name = "ListeFichiersEtDossiers"
Option Explicit
'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Sub ListFiles()
Dim msg As String, answer As String
Dim Directory As String
Dim R As Integer
Dim i As Integer
Dim StartDate As Single
msg = "Select a location containing the files you want to list."
Directory = GetDirectory(msg)
If Directory = "" Then Exit Sub
If Right(Directory, 1) <> "\" Then Directory = Directory & "\"
' Insert headers
R = ActiveCell.Row
Cells(R, 1) = "FilePath"
Cells(R, 2) = "Size"
Cells(R, 3) = "Date/Time"
Cells(R, 4) = "Filename"
Range("A1:C1").Font.Bold = True
R = R + 1
On Error Resume Next
With Application.FileSearch
.NewSearch
.LookIn = Directory
.Filename = "*.*" ' this can be '*.*
.SearchSubFolders = True
.Execute
For i = 1 To .FoundFiles.Count
If FileDateTime(.FoundFiles(i)) > StartDate Then
Cells(R, 1) = .FoundFiles(i)
Cells(R, 4) = Right(Cells(R, 1), Len(.FoundFiles(i)) - InStrRev(Cells(R, 1).Value, "\"))
Cells(R, 2) = FileLen(.FoundFiles(i))
Cells(R, 3) = FileDateTime(.FoundFiles(i))
R = R + 1
End If
Next i
End With
'Columns("A:C").Select
'Selection.Columns.AutoFit
'ActiveSheet.Columns("1:3").AutoFit
MsgBox "file listing complete"
End Sub
Function GetDirectory(Optional msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim R As Long, x As Long, pos As Integer
' Root folder = Desktop
bInfo.pidlRoot = 0&
' Title in the dialog
If IsMissing(msg) Then
bInfo.lpszTitle = "Select a folder"
Else
bInfo.lpszTitle = msg
End If
' Type of directory to return
bInfo.ulFlags = &H1
' Display the dialog
x = SHBrowseForFolder(bInfo)
' Parse the result
path = Space$(512)
R = SHGetPathFromIDList(ByVal x, ByVal path)
If R Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
Else
GetDirectory = ""
End If
End Function
Function InStrLast(iStart As Integer, szSrchIn As String, _
szSrchFor As String, iCompare As Integer) As Integer
Dim iPrevFoundAt As Integer
Dim iFoundAt As Integer
On Error GoTo ErrExit_InStrLast
iPrevFoundAt = 0
iFoundAt = InStr(iStart, szSrchIn, szSrchFor, iCompare)
Do While iFoundAt > 0
iPrevFoundAt = iFoundAt
iFoundAt = InStr(iPrevFoundAt + 1, szSrchIn, szSrchFor, iCompare)
Loop
ErrExit_InStrLast:
If Err <> 0 Then MsgBox Error$, vbExclamation
InStrLast = iPrevFoundAt
Exit Function
End Function
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
ASYNC/AWAIT: COMPRENDRE COMMENT CA MARCHEASYNC/AWAIT: COMPRENDRE COMMENT CA MARCHE par fathi
Tout le monde est unanime pour dire que la programmation multi-thread et asynchrone est en train de devenir un sujet incontournable. Beaucoup de choses sont arrivées avec le framework 4 pour le code parallèle (TPL, PLinq,.) et bientôt, on va avoir l...
Cliquez pour lire la suite de l'article par fathi PAS D'INTELLITRACE SUR MON SITE WEB DANS IIS !PAS D'INTELLITRACE SUR MON SITE WEB DANS IIS ! par Etienne Margraff
J'ai récemment eu un problème pour obtenir l'intelliTrace sur un site web dans IIS. Il n'y avait pas de message d'erreur, rien dans le journal d'évènement Windows, et après 3 appels à une voyante, 2 visites chez un marabou, j'ai failli me résign...
Cliquez pour lire la suite de l'article par Etienne Margraff OFFICE 365 - SHAREPOINT ONLINE, QUELQUES LIMITATIONSOFFICE 365 - SHAREPOINT ONLINE, QUELQUES LIMITATIONS par junarnoalg
De nombreuses entreprises font le choix de SharePoint Online, service fourni au travers de l'offre de Microsoft Office 365. S'il est vrai que ce choix apporte un grand nombre d'avantages; rapidité de mise en œuvre, disponibilité, large couvertu...
Cliquez pour lire la suite de l'article par junarnoalg PRéSENTATION DES API REST DE WINDOWS AZURE : LISTER LES COMPTES DE STORAGEPRéSENTATION DES API REST DE WINDOWS AZURE : LISTER LES COMPTES DE STORAGE par richardc
http://www.c2idotnet.com/articles/presentation-des-api-rest-de-windows-azure-lister-les-comptes-de-storage
Désolé pour "toto", mais c2i existait avant blogs.developpeur.org et c'est mon site "officiel" ;-) ...
Cliquez pour lire la suite de l'article par richardc
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|