摘要:如何取得裝置上Flash Card的名稱
智慧型裝置近來越來越流行了,iPhone跟HTC Touch系 列的手機更是夯(ㄏㄤ)到不行,搭載Windows Mobile系列OS的機子也越來越多了,但是各家對於FlashCard的名稱卻是各不相同,像是我的叫做"儲存卡",有的叫做"SD Card",有的叫做"storage card";那麼我們在寫作程式的時候怎麼辦?如果要寫入一個檔案到FlashCard裡面,像是在MSDN上面的這個問題"PDA 寫入txt檔",如果像下面這樣子寫
- Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter("\SD Card\test.txt")
- sw.Write(Level4.Text & "#")
- sw.Write(Level5.Text & "#")
- sw.Write(Level1.Text & "#")
- sw.Write(Level2.Text & "#")
- sw.Write(Level3.Text & "#")
- sw.Close()
Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter("\SD Card\test.txt")
sw.Write(Level4.Text & "#")
sw.Write(Level5.Text & "#")
sw.Write(Level1.Text & "#")
sw.Write(Level2.Text & "#")
sw.Write(Level3.Text & "#")
sw.Close()
雖然可以正常執行,但是換了一個機子可能就會發生錯誤了,那麼應該怎麼做呢?下面是一些參考資料
- how to create file
- Hard-coding "My Documents"? Fix Your Code on Windows Mobile Team Blog
下面是節錄自MSDN Forums的程式碼
- ' Enumerating all subfolders in a root folder...
- For Each directory As String In System.IO.Directory.GetDirectories("\")
- ' Picking folders with Temporary attribute set...
- If ((New System.IO.DirectoryInfo(directory)).Attributes And IO.FileAttributes.Temporary) <> 0 Then
- Console.WriteLine("Found storage card: {0}", directory)
- End If
- Next