Search device for files...

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
 
B

Brian H

Hi there,

I use Path.DirectorySeparatorChar.ToString() for the root directory...

Thanks for the help!
Brian
 
B

Brian H

I don't know 100% for sure, since I'm not there at the device -- but I know
for sure it's in the CheckPathForMedia method. I tried commenting out the
first for...each block, thinking it would be erroring in there, but my test
user reports the same problem. So, my hunch is either the GetFiles or
GetDirectories is what's tripping it up. If I had the device in front of
me, I could give more useful info :)

Thanks for your help,
Brian
 
B

Brian H

Hi all,

Problem resolved. Turns out a particular directory in the file system was
corrupt. After deleting the directory, it began working fine.

Thanks for your help,
Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top