Simple question about File System

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
 
S

Scott Allen

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top