How can I add only files that already exits and file that just created in Listbox? I have set Timer on this sub.

Dim XDir As DirectoryInfo = New DirectoryInfo(Trim("" & Me.txtPathX.Text & ""))

Dim ExtraCount As Integer

Dim myfileInfo as fileinfo

For Each myfileInfo In XDir.GetFiles

ExtraCount = XDir.GetFiles.Length

Me.lblCountExtra.Text = ExtraCount.ToString

Me.ListBox2.Items.Add(myfileInfo.CreationTime)  -------------------- This line just keepS adding the same file(Time it is created) over and over


If ExtraCount = Nothing Then

Me.lblCountExtra.Text = CStr(0)

End If
Who is Participating?
What I have understood is that you need a directory watcher
Mike TomlinsonMiddle School Assistant TeacherCommented:
Can you explain in plain english what the code is ~supposed~ to accomplish?   =)
look for FileSystemWatcher class in MSDN
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

VBdotnet2005Author Commented:
Idle_Mind ,

I want to add a file name and time in a folder to a list box when a new file is added and keep track of how many item in a list box. FileSystemWatcher class?
Mike TomlinsonMiddle School Assistant TeacherCommented:
Yes...I think armoghan was right on with the FileSystemWatcher.
VBdotnet2005Author Commented:
thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.