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
Printable View
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
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
VB Code:
Dim DirInfo As New System.IO.DirectoryInfo("C:\some directory\") MessageBox.Show("Total Files: " & DirInfo.GetFiles.GetLowerBound(0).ToString)
VB Code:
If IO.Directory.GetDirectories(folderPath).Length = 0 Then MessageBox.Show("The folder contains no subfolders.") End If If IO.Directory.GetFiles(folderPath).Length = 0 Then MessageBox.Show("The folder contains no files.") End If If IO.Directory.GetFileSystemEntries(folderPath).Length = 0 Then MessageBox.Show("The folder contains no files or subfolders.") End If If My.Computer.FileSystem.GetDirectories(folderPath).Count = 0 Then MessageBox.Show("The folder contains no subfolders.") End If If My.Computer.FileSystem.GetFiles(folderPath).Count = 0 Then MessageBox.Show("The folder contains no files.") End If