Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Anzahl Dateien im Verzeichnis und Unterordner auslesen

Empfohlene Antworten

Veröffentlicht

Hallo Leute,

ich würde gern die Anzahl von allen Dateien im Verzeichnis inkl. Unterordner auslesen.

Als Basis habe ich das hier gefunden:


Dim counter = My.Computer.FileSystem.GetFiles("[COLOR="#FF0000"]Das zu durchsuchende Verzeichnis[/COLOR]")

MsgBox("number of files is " & CStr(counter.Count))

- Wie schaffe ich es, dass dieser Code auch die Unterordner mit einbezieht?

- Ist die Variable "counter" eine Integervariable?

Gruß und danke

Rien

  • Autor

Ja, muss ich noch dazu sagen, dass ich nicht ausgegeben haben möchte wieviele Unterverzeichnisse es gibt.

Ich meinte er sollte auch die Unterverzeichnisse nach Dateien absuchen.

Aber danke schonmal, werd es mir mal durchlesen

  • Autor

Gut, ich habe es hinbekommen

Lösung:


[COLOR="#0000FF"]Dim [/COLOR]di [COLOR="#0000FF"]As New[/COLOR] System.IO.[COLOR="#40E0D0"]DirectoryInfo[/COLOR](myargs(1))

        [COLOR="#0000FF"]For Each[/COLOR] fi [COLOR="#0000FF"]As[/COLOR] System.IO.[COLOR="#40E0D0"]FileInfo [/COLOR][COLOR="#0000FF"]In[/COLOR] di.GetFiles([COLOR="#B22222"]"*.*"[/COLOR], System.IO.[COLOR="#40E0D0"]SearchOption[/COLOR].AllDirectories)

            counter = counter + 1

        [COLOR="#0000FF"]Next[/COLOR]

[COLOR="#008000"]'Gibt die Anzahl an Files aus; rein zu Prüfung[/COLOR]

MsgBox(counter)

Das ist ist doch schon mal gut.

GetFiles() liefert ein Array. Ein Count erspart dir die Schleife.

di.GetFiles("*.*", SearchOption.AllDirectories).Count()
oder
dim count = New DirectoryInfo(myargs(1)).GetFiles("*.*", SearchOption.AllDirectories).Count()

myargs solltest du noch auf null bzw. count > 0 überprüfen, damit es keine NullReferenceException gibt.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.