Need to list files in a directory on ipaq

  • Thread starter Thread starter winn
  • Start date Start date
W

winn

I have extracted the following code from
http://msdn.microsoft.com/library/d...html/frlrfsystemiodirectoryinfoclasstopic.asp

I am new to .net and I was simply wondering how to use this code in vb,
i.e. to where exactly do I paste this code. Normally we have Form_Load
rather than Main ?

Imports System
Imports System.IO

Public Class Test
Public Shared Sub Main()
' Specify the directories you want to manipulate.
Dim di As DirectoryInfo = New DirectoryInfo("c:\MyDir")
Try
' Determine whether the directory exists.
If di.Exists Then
' Indicate that it already exists.
Console.WriteLine("That path exists already.")
Return
End If

Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Class
 
The code example you've posted doesn't seem to be of any use for displaying
a list of files. Assuming you have a new Smart Device Application project,
add a ListBox control to the form. Then in your Form_Load method add the
following:-

'create new directory info object for folder
Dim di As New DirectoryInfo("\My Documents")

'get all items in the folder
Dim fia() As FileInfo
fia = di.GetFiles()

'display the name of the file
ListBox1.DisplayMember = "Name"
'bind listbox to list of file information items
ListBox1.DataSource = fia

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
 
You are really helping a lot, thanks. Now, I am almost finished,
but I need to save all the items in the list box in a simple text
file. I found some code from msdn, but I am not sure how to
iterate the list, is there a simple way to output the entire list
to a file in one go? Here is what I found

' Create an instance of StreamWriter to write text to a file.

Dim sw As StreamWriter = New StreamWriter("TestFile.txt")

' Add some text to the file.

sw.WriteLine("header for the file.")

sw.WriteLine("-------------------")

' Arbitrary objects can also be written to the file.

' iterare through items here

sw.Close()
 
I have done it. I added this

Dim i

For i = 0 To ListBox1.Items.Count - 1

sw.WriteLine(ListBox1.Items(i))

Next



Thanks
 
Back
Top