thomas1972
Goto Top

Access - VBA - Anzahl von Unterordnern in Access, DIR funktion liefert falsches Ergebnis

Hallo,
ich versuche aus einem Verzeichnis die Anzahl Unterordner sowie die Anzahl von Dateien auszulesen

Leider erkennt dieser sowohl die Anzahl der Unterordnern, sowie die Anzahl der Dateien in einem .

Beispielordner c:\temp
4 Unterordner und
3 Dateien

c:\temp\ = attach_path_vpdid


Ergebnis

Ordner = 7 -> hier sollte nur 4 stehen
Anzahl Dateien = 3 -> Soweit richtig

     Dim strvpdid, strbtnr As String
     Dim intz, intz2 As Integer
     
  'Anzahl Subfolder         
         strvpdid = Dir(attach_path_vpdid & "\", vbDirectory)  
         
         Do While strvpdid <> ""  
             strvpdid = Dir
             intz = intz + 1
         Debug.Print strvpdid
         Loop
         intz = intz - 2     ' -2 aufgrund der Gefundenen Ordner "." + ".."  
         Forms!Testform!anzahl_unterordner_vpdid = intz
         intz = ""  
         
' anzahl Dateien ausgeben  
         strvpdid = Dir(attach_path_vpdid & "\", vbNormal)  
         
         Do While strvpdid <> ""  
             strvpdid = Dir
             intz2 = intz2 + 1
             
         Loop
         Forms!Testform!anzahl_files_vpdid = intz2
         intz2 = ""  

Ist die Dir Funktion nicht dafür die richtige?

Grüße aus München

Content-Key: 308580

Url: https://administrator.de/contentid/308580

Printed on: April 26, 2024 at 00:04 o'clock

Mitglied: 129813
Solution 129813 Jun 30, 2016 updated at 11:25:40 (UTC)
Goto Top
Hi.
Use the FileSystemObject:
Set fso = CreateObject("Scripting.FileSystemObject")  
set folder = fso.GetFolder("C:\FOLDERXYZ")  
folderCount = folder.SubFolders.Count
fileCount = folder.Files.Count
Regards
Member: thomas1972
thomas1972 Jun 30, 2016 at 12:00:52 (UTC)
Goto Top
Thanks for the information