Results 1 to 4 of 4

Thread: Empty Directory

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    9

    Empty Directory

    Hi

    I am having troubles figuring out how to find if a directory is empty.

    I am trying to us my.computer.filesystem.

    but I am not having any luck

  2. #2
    Addicted Member bgard68's Avatar
    Join Date
    Mar 2006
    Location
    Arkansas
    Posts
    164

    Re: Empty Directory

    Try using the System.IO namespace,
    for example:

    'Dont forget to supply the path of the directory you want to test

    Private Sub ShowFiles(ByVal path As String)

    Dim strFiles() As String

    strFiles = System.IO.Directory.GetFiles(path)

    If strFiles.Length <= 0 Then
    MessageBox.Show("There are no files in this direcotry")
    Else
    'Do some code
    End If

    End Sub
    Using Framework 1.1, VB.Net 2003 unless I
    state otherwise

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Empty Directory

    VB Code:
    1. Dim DirInfo As New System.IO.DirectoryInfo("C:\some directory\")
    2.         MessageBox.Show("Total Files: " & DirInfo.GetFiles.GetLowerBound(0).ToString)

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Empty Directory

    VB Code:
    1. If IO.Directory.GetDirectories(folderPath).Length = 0 Then
    2.             MessageBox.Show("The folder contains no subfolders.")
    3.         End If
    4.  
    5.         If IO.Directory.GetFiles(folderPath).Length = 0 Then
    6.             MessageBox.Show("The folder contains no files.")
    7.         End If
    8.  
    9.         If IO.Directory.GetFileSystemEntries(folderPath).Length = 0 Then
    10.             MessageBox.Show("The folder contains no files or subfolders.")
    11.         End If
    12.  
    13.         If My.Computer.FileSystem.GetDirectories(folderPath).Count = 0 Then
    14.             MessageBox.Show("The folder contains no subfolders.")
    15.         End If
    16.  
    17.         If My.Computer.FileSystem.GetFiles(folderPath).Count = 0 Then
    18.             MessageBox.Show("The folder contains no files.")
    19.         End If
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width