Dateien eines Verzeichnisbaumes auslesen

Dateien eines Verzeichnisbaumes auslesen: FindFirstFile, FindNextFile, FindClose
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" _
(ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private nCount&
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Const MAX_PATH = 260
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Function to calculate bytes used in Root$ and all subdirectories of Root$
Function GetDirectoryListing(ByVal Root$)
Dim FData As WIN32_FIND_DATA Root$ should be entered in the form C:\Dir
Dim fHand&
Dim sPath$
Dim StillOK&
Dim ByteTotal&
Dim nPos%
Dim DirName$, FileName$
sPath$ = Root$ + "\*.*"
fHand& = FindFirstFile(sPath$, FData)
If fHand& <= 0 Then
Exit Function
End If
ByteTotal& = 0
Do
If (FData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY Then
nPos% = InStr(FData.cFileName, Chr$(0))
DirName$ = Left$(FData.cFileName, nPos% - 1)
If DirName$ <> "." And DirName$ <> ".." Then
GetDirectoryListing Root$ + "\" + DirName$
End If
Else
nCount& = nCount& + 1
nPos% = InStr(FData.cFileName, Chr$(0))
FileName$ = Left$(FData.cFileName, nPos% - 1)
frmFileName.List1.AddItem Root$ + "\" + FileName Ausgabe in ListBox (Dateinamen & Pfad)
Cells(nCount&, 1).Value = Root$ + "\" + FileName Ausgabe in Excel-Zelle (Dateinamen & Pfad)
Cells(nCount&,1).Value = FileName$ Ausgabe in Excel-Zelle (nur Dateinamen)
End If
StillOK& = FindNextFile(fHand&, FData)
Loop Until StillOK = 0
fHand& = FindClose(fHand&)
End Function
Sub GetFileList()
Dim Path$, nCount&
nCount& = 0
Path$ = InputBox("Enter the root for the file listing (e.g. 'c:\dir' or c:")
If Len(Path$) = 0 Then Exit Sub
GetDirectoryListing Path$
End Sub
Sponsoren und Investoren

Sponsoren und Investoren sind jederzeit herzlich willkommen!
Wenn Sie die Information(en) auf dieser Seite interessant fanden, freuen wir uns über eine kleine Spende. Empfehlen Sie uns bitte auch in Ihren Netzwerken (z. B. Twitter, Facebook oder Google+). Herzlichen Dank!

Nach oben Sitemap
Impressum & Kontakt