Simple question about File System

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a following code which I use to display the files in a directory
named Temp. If the Temp directory doesn’t have any files, then I want to
display a message but I don’t know how to find it out if the directory is
empty or has any files. Can some someone help me?

Thanks,

Joe

Dim strFilePath As String = "E:\Temp"
If Not Page.IsPostBack then
Dim dirInfo As New DirectoryInfo(strFilePath)

articleList.DataSource = dirInfo.GetFiles("*.*")
articleList.DataBind()
End If
 
Joe:

GetFiles returns an array of FileInfo.

You can always check the Length property of an array to see if it is
empty.

ie:

FileInfo[] files = dirInfo.GetFiles("*.*");

if(files.Length == 0)
{
// no files for you...
}

HTH,
 
Back
Top