DirectoryNotFoundException on compact framework

davidh

Active member
Joined
Jul 8, 2003
Messages
31
Location
UK
Hi,

Im trying to do a simple search of files of a certain type on a pocket pc. I pulled the code below off the internet but keep getting a DirectoryNotFoundException on the New DirectoryInfo(Directory) line. Although Ive got "\Storage Card" on this example Ive tried it with \Program Files and various other folders that are always there. It fails both on the emulator and on the device itself.

Any clues on what Im doing wrong would be greatfully appreciated

Thanks

Dave

Code:
        Try
            Dim di As DirectoryInfo = New DirectoryInfo("\Storage Card")
            Dim dirs As DirectoryInfo() = di.GetDirectories()
            Dim s As String() = Directory.GetFiles("*.tga")
            ListBox1.Items.Add("Number of guides on storage card is " & s.GetLength(0))
            ListBox1.Items.Add("Number of directories on card is " & dirs.Length)

            Dim diNext As DirectoryInfo
            For Each diNext In dirs
                ListBox1.Items.Add("The number of guides in " & diNext.Name & " with is " & diNext.GetFiles("*.tga").Length)
            Next

        Catch ex As Exception
            MessageBox.Show("The process failed: " & ex.ToString())
        End Try
 
It should be
@"\Storage Card"
or
"\\Storage Card"

It wont work on the emulator because the emulator doesnt have a storage card.
 
If I try @"\Storage Card" the project no longer compiles, it complains about an invalid character, and if I try "\\Storage Card", or "\\Program Files" on the emulator, the exception now changes to System.IO.IOException instead of the original DirectoryNotFoundException.
 
Actually I notice it now falls over on the next line where Im trying to call di.GetDirectories().
 
Using the @ symbol or the \\ notation is only required in C# where \ is used to denote escape sequences, under VB the \ character doesnt have any special meaning.
 
Ok, taken the \\ out and replaced with \ and it all works fine now. Thanks for your help.
 
Back
Top