Creating a directory navigator?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Creating a directory navigator?

  1. #1
    Join Date
    Jan 2012
    Posts
    27

    Creating a directory navigator?

    I could not find anything on Google, I thought id try here.

    I have a program that will look in a specific directory the user selects (Lets use the Desktop for example)

    Now, this user can see everything on their desktop from this program, in the form of a listbox.

    Now, lets say this person has a folder on the desktop called "aaaa" and inside that "bbbb" and inside that, "ccccc".

    They want to go inside aaaa, so they doubble click on the folder "aaaa" from the listbox.

    Now, lets say they navigate into bbbb, and they want to go back out into aaaa from the program, they would press the "back" button instead of the "forward" button.

    My question is: How exactly is a "back" and "forward" button constructed?
    Right now, all I could figure out, is how to navigate them to 1 folder up, so if there on the desktop, then I can have it navigate them to aaaa, however, if they try to click on bbbb, the program will try to go to the desktop, and proceed 1 lvl up, which would be aaa, so it will crash.

    Code:
    IO.Directory.GetDirectories(My.Computer.FileSystem.SpecialDirectories.Desktop & "/" & Listbox1.SelectedItem)

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,092

    Re: Creating a directory navigator?

    This may be too complicated for an example, but it should still prove useful :

    http://forums.codeguru.com/showthrea...er-Application

    I hope it helps!

  3. #3
    Join Date
    Jan 2012
    Posts
    27

    Re: Creating a directory navigator?

    Im sorry, I still dont understand it.
    Is there a simpler way to execute a forward? Cause what I have now is:
    Code:
    Dim currentDirectory As String = Nothing
    
    Private Sub currentdirectorysearch_DoubleClick(sender As System.Object, e As System.EventArgs) Handles currentdirectorysearch.DoubleClick
            Dim currentDirectory As String = Nothing
    
            'For Each directory In currentdirectorysearch.Items
            Try
                currentDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop & "/" & currentdirectorysearch.SelectedItem
    
                Dim files = IO.Directory.GetFiles(My.Computer.FileSystem.SpecialDirectories.Desktop & "/" & currentdirectorysearch.SelectedItem)
                Dim folders = IO.Directory.GetDirectories(My.Computer.FileSystem.SpecialDirectories.Desktop & "/" & currentdirectorysearch.SelectedItem)
                Dim q = From file In files _
                      Select IO.Path.GetFileName(file)
                Dim r = From folder In folders _
                      Select IO.Path.GetFileName(folder)
    
                currentdirectorysearch.Items.Clear()
                currentdirectorysearch.Items.AddRange(q.ToArray)
                currentdirectorysearch.Items.AddRange(r.ToArray)
            Catch ex As Exception
                currentDirectory &= "/" & currentdirectorysearch.SelectedItem
                Dim files = IO.Directory.GetFiles(currentDirectory)
                Dim folders = IO.Directory.GetDirectories(currentDirectory)
                Dim q = From file In files _
                      Select IO.Path.GetFileName(file)
                Dim r = From folder In folders _
                      Select IO.Path.GetFileName(folder)
    
                currentdirectorysearch.Items.Clear()
                currentdirectorysearch.Items.AddRange(q.ToArray)
                currentdirectorysearch.Items.AddRange(r.ToArray)
            End Try
        End Sub
    So I have 2 listboxes, and pretty much, when an item in this specific listbox is double clicked, it will try to go inside that directory and save the old directory path (for incase you want to go back)
    what its doing is taking the new path as the old path, and then adding the new path onto it
    So, if you go into "aaaaa" on your desktop, it will open it, because it will do ".../.../.../Desktp/aaaaa" then if you try to go into lets say bbbbbb inside that aaaaa folder, it will fail because its then doing: ".../.../.../Desktop/bbbbb/bbbbb"
    Its not leaving it with the old directory of "aaaaa"... How would I do that?
    And I think its because of
    Code:
    currentDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop & "/" & currentdirectorysearch.SelectedItem
    But I dont know how to fix it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center