filesystem...

Q

Quentin

also die möglichkeiten mit FILESYSTEM sind ja doch ziemlich beschränkt. wie finde ich raus wieviele files in einem ordner sind? eine filelistbox will ich nicht verwenden.. wär aber meine letzte alternative eine unsichtbare filelistbox herzunehmen...

kennt jemand eine möglichkeit ohne filelistbox?

thx & greetz
q
 
Code:
Private Declare Sub FindClose Lib "kernel32" (ByVal hFindFile As Long)
Private Declare Function FindFirstFileA Lib "kernel32" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFileA Lib "kernel32" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function GetFileAttributesA Lib "kernel32" (ByVal lpFileName As String) As Long

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 * 260
    cAlternate As String * 14
End Type

Public Function FindFiles(ByVal Path As String, ByRef Files As Collection, Optional ByVal Pattern As String = "*.*", Optional ByVal Attributes As VbFileAttribute = vbNormal, Optional ByVal Recursive As Boolean = True) As Long
Dim FileAttr As Long
Dim FileName As String
Dim hFind As Long
Dim WFD As WIN32_FIND_DATA
  
'Initialisierung:
If Right$(Path, 1) <> "\" Then Path = Path & "\"
If Files Is Nothing Then Set Files = New Collection
Pattern = LCase$(Pattern)
  
'Suche starten:
hFind = FindFirstFileA(Path & "*", WFD)
If hFind = -1 Then
    Err.Raise 76 'Verzeichnis nicht gefunden
End If

'Suche fortsetzen:
Do While FindNextFileA(hFind, WFD)
    FileName = LeftB$(WFD.cFileName, _
    InStrB(WFD.cFileName, vbNullChar))
    FileAttr = GetFileAttributesA(Path & FileName)

    If Not (FileAttr Or vbDirectory) Then

    'Datei analysieren:
        If (FileAttr And Attributes) = Attributes Then
            If LCase$(FileName) Like Pattern Then
                FindFiles = FindFiles + 1
                Files.Add Path & FileName
            End If
        End If

    End If
Loop

FindClose hFind

End Function
viel spass :)
 
merci
i'll have a look
wie ich dich kenne wirds eh funktioniern

danke!
 
version 2.0

Code:
Private Declare Sub FindClose Lib "kernel32" (ByVal hFindFile As Long)
Private Declare Function FindFirstFileA Lib "kernel32" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFileA Lib "kernel32" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function GetFileAttributesA Lib "kernel32" (ByVal lpFileName As String) As Long

Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type

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 * 260
    cAlternate As String * 14
End Type

Public Function FindFiles(ByVal Path As String, Optional ByVal Pattern As String = "*.*", Optional ByVal Attributes As VbFileAttribute = vbNormal) As Long
Dim FileAttr As Long
Dim FileName As String
Dim hFind As Long
Dim WFD As WIN32_FIND_DATA
  
'Initialisierung:
If Right(Path, 1) <> "\" Then Path = Path & "\"
Pattern = LCase(Pattern)
  
'Suche starten:
hFind = FindFirstFileA(Path & "*", WFD)
If hFind = -1 Then
    Err.Raise 76 'Verzeichnis nicht gefunden
End If

'Suche fortsetzen:
Do While FindNextFileA(hFind, WFD)
    FileName = LeftB(WFD.cFileName, InStrB(WFD.cFileName, vbNullChar))
    FileAttr = GetFileAttributesA(Path & FileName)

    If FileAttr And Not vbDirectory Then

    'Datei analysieren:
        If (FileAttr And Attributes) = Attributes Then
            If LCase(FileName) Like Pattern Then
                FindFiles = FindFiles + 1
                List1.AddItem Path & FileName
            End If
        End If

    End If
Loop

FindClose hFind

End Function

soweit ich das sehe, sind jetzt so ziemlich alle fehler raus. mit den dateiattributen musst du einfach selber etwas rumexperimentieren. ;)
 
*hust*
*duck*
habs dir eh im icq erklärt

aber 100000 dank trotzdem =)

greetz
q
 
Also das geht doch wesentlich kürzer und ohne API. Wobei der weg über die API schon was hat *g*
Ich würde das so machen, wenn man nur die Anzahl der dateien in einem bestimmten ordner braucht:
Code:
Dim fso, file, f1, folder
Dim counter As Integer
Dim ordner as String
ordner = "C:\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.GetFolder(ordner)
Set folder = file.Files
counter = 0
For Each f1 In folder
    counter = counter + 1
Next
MsgBox counter

Gruss Homer
 
genau so hab ichs auch gemacht ;)

wusste vorher nie wie ich das FSO einbinden kann weil mir keiner gesagt hat das ich einfach nur die scripting runtime einbinden muss *grml* =)

danke trotzdem ;)
 
Zurück