Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27199

vb 2102 - list/recurse empty folders or folders with specific files. Complete newbie.

$
0
0
Hello everybody,
I am stupid... I mean simple. Please answer accordingly. 'Comment your code'!
[Problem]
I am trying to use my Windows Desktop form to display a list of 'empty' folders and sub folders in a listbox. I will eventually be aiming to delete all or just selected listed folders. My example scenario is: User has moved MOST *.files from one root directory to another storage directory. Let's say *.MP3 but could be any file extension. The root directory is added to and updated frequently and then some/most/all *.MP3 are removed to a new directory. Leaving residual .desktop.ini, albumart, .lnk and .url files and more, but also some folders have the precious *.MP3.
There is no limit to the number of sub folders. I am trying to recurse them all.
[Code thus far]
I have this which lists the directories (but not sub directories) and I'm certain that even this could be tidied in to a few tidy lines.

Code:

Private Sub ButtonBrowse_Click(sender As Object, e As EventArgs) Handles ButtonBrowse.Click
        Dim foundfolder As String
        Dim RootDir As String
    FolderBrowserDialog1.ShowDialog()
        RootDir = FolderBrowserDialog1.SelectedPath
        TextBoxPath.Text = RootDir
      For Each foundfolder In My.Computer.FileSystem.GetDirectories(RootDir)
            ListBox1.Items.Add(foundfolder)
        Next
'The aboves is an entire directory listing. I only want empty folders and sub folders.
'NOTE: By empty folders, I mean including empty sub folders sub sub folders (ad infinitum) or any of those folders containing desktop.ini or .lnk or any 'hidden files/folders.

        ' Dim FileCount As Integer = IO.Directory.GetDirectories(RootDir).Length
        ' MsgBox(FileCount)
    End Sub

[NOTES]
. Not interested in 'Why are you bothering'. The answer is because I want to. I like 'seeing' things and results of efforts and learning. And a form and vb is what I like. Batch and vbs would warrant a different site. (possibly)

.Not interested in people arguing. I've done lots of searching and reading and pretty much every post I read on quite a number of sites ends with a mild bitterness. The reason being each and all have a different opinion. I LIKE all opinions. Refrain from mentioning or correcting others. Each opinion is valued and is as important as much as yours :)

. I'm dumb. I learn slowly and try hard to teach myself from what I read before asking. So thank you for your patience. :)

:duck:

Viewing all articles
Browse latest Browse all 27199

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>