B
Brian H
Hi all,
I have a filedialog form in vb.net (very similar to the one that is included
with VS.NET) that basically searches a device for media files, and displays
them in a treeview. Instead of being a tree for the entire device, it will
only display those subdirectories that have media files. I'm having an
issue with this running on Pocket PC Chinese versions. Basically it's
throwing an IO exception; at this time I don't have any further info on the
error. Still working on a faster solution as this has some redundancies
that slows it down, but here's the jist of my first incarnation:
Anyone know why this would trip up Chinese versions?
Form load:
Cursor.Current = Cursors.WaitCursor
tvwDirectories.Indent = 2
Dim root As TreeNode =
tvwDirectories.Nodes.Add(Path.DirectorySeparatorChar.ToString())
root.Tag = Path.DirectorySeparatorChar.ToString()
PopulateTreeView(root, Path.DirectorySeparatorChar.ToString())
tvwDirectories.CollapseAll()
Cursor.Current = Cursors.Default
Private Sub PopulateTreeView(ByVal Node As TreeNode, ByVal dir As String)
Try
Dim subdirs As String() = Directory.GetDirectories(dir)
Array.Sort(subdirs)
For Each subdir As String In subdirs
'check if a media file exists here
If CheckPathForMedia(subdir) Then
'add subdir to the tree
Dim subNode As TreeNode = New
TreeNode(Path.GetFileName(subdir))
subNode.Tag = subdir
Node.Nodes.Add(subNode)
'get the files in this subdir
Dim files As String() = Directory.GetFiles(subdir)
Array.Sort(files)
For Each dirFile As String In files
Dim shortFileName As String =
dirFile.Substring(dirFile.LastIndexOf(Path.DirectorySeparatorChar.ToString)
+ 1)
If isValidFileType(shortFileName) Then
Dim fileNode As TreeNode = New
TreeNode(shortFileName)
fileNode.Tag = dirFile
subNode.Nodes.Add(fileNode)
End If
Next
PopulateTreeView(subNode, subdir)
End If
Next
Catch ex As Exception
MsgBox("Populate Tree: " & ex.Message.ToString())
Me.Close()
End Try
End Sub
Private Function CheckPathForMedia(ByVal dir As String) As Boolean
Try
Dim result As Boolean = False
'check local files
Dim lfiles As String() = Directory.GetFiles(dir)
For Each dirFile As String In lfiles
Dim shortFileName As String =
dirFile.Substring(dirFile.LastIndexOf(Path.DirectorySeparatorChar.ToString)
+ 1)
If isValidFileType(shortFileName.ToString.ToLower) Then
Return True
End If
Next
Dim subdirs As String() = Directory.GetDirectories(dir)
For Each subdir As String In subdirs
If CheckPathForMedia(subdir) Then
Return True
End If
Next
Catch ex As Exception
MsgBox("CheckPath: " & ex.Message.ToString())
Me.Close()
End Try
Return False
End Function
I have a filedialog form in vb.net (very similar to the one that is included
with VS.NET) that basically searches a device for media files, and displays
them in a treeview. Instead of being a tree for the entire device, it will
only display those subdirectories that have media files. I'm having an
issue with this running on Pocket PC Chinese versions. Basically it's
throwing an IO exception; at this time I don't have any further info on the
error. Still working on a faster solution as this has some redundancies
that slows it down, but here's the jist of my first incarnation:
Anyone know why this would trip up Chinese versions?
Form load:
Cursor.Current = Cursors.WaitCursor
tvwDirectories.Indent = 2
Dim root As TreeNode =
tvwDirectories.Nodes.Add(Path.DirectorySeparatorChar.ToString())
root.Tag = Path.DirectorySeparatorChar.ToString()
PopulateTreeView(root, Path.DirectorySeparatorChar.ToString())
tvwDirectories.CollapseAll()
Cursor.Current = Cursors.Default
Private Sub PopulateTreeView(ByVal Node As TreeNode, ByVal dir As String)
Try
Dim subdirs As String() = Directory.GetDirectories(dir)
Array.Sort(subdirs)
For Each subdir As String In subdirs
'check if a media file exists here
If CheckPathForMedia(subdir) Then
'add subdir to the tree
Dim subNode As TreeNode = New
TreeNode(Path.GetFileName(subdir))
subNode.Tag = subdir
Node.Nodes.Add(subNode)
'get the files in this subdir
Dim files As String() = Directory.GetFiles(subdir)
Array.Sort(files)
For Each dirFile As String In files
Dim shortFileName As String =
dirFile.Substring(dirFile.LastIndexOf(Path.DirectorySeparatorChar.ToString)
+ 1)
If isValidFileType(shortFileName) Then
Dim fileNode As TreeNode = New
TreeNode(shortFileName)
fileNode.Tag = dirFile
subNode.Nodes.Add(fileNode)
End If
Next
PopulateTreeView(subNode, subdir)
End If
Next
Catch ex As Exception
MsgBox("Populate Tree: " & ex.Message.ToString())
Me.Close()
End Try
End Sub
Private Function CheckPathForMedia(ByVal dir As String) As Boolean
Try
Dim result As Boolean = False
'check local files
Dim lfiles As String() = Directory.GetFiles(dir)
For Each dirFile As String In lfiles
Dim shortFileName As String =
dirFile.Substring(dirFile.LastIndexOf(Path.DirectorySeparatorChar.ToString)
+ 1)
If isValidFileType(shortFileName.ToString.ToLower) Then
Return True
End If
Next
Dim subdirs As String() = Directory.GetDirectories(dir)
For Each subdir As String In subdirs
If CheckPathForMedia(subdir) Then
Return True
End If
Next
Catch ex As Exception
MsgBox("CheckPath: " & ex.Message.ToString())
Me.Close()
End Try
Return False
End Function