Results 1 to 11 of 11

Thread: [2008] read a directory tree

Hybrid View

  1. #1
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2008] read a directory tree

    vb Code:
    1. dim path as string = "c:\windows\system32\drivers\cabs"
    2. dim depth as integer = 3
    3. dim tempArray() as string = path.split("\")
    4.  
    5. dim newPath as string
    6. for x as integer = 1 to depth
    7.     newPath &= tempArray(x-1) & "\"
    8. next

    or

    io.Directory.GetParent

  2. #2
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: [2008] read a directory tree

    Directory.GetParent() would be like this:
    Code:
    Imports System.IO
    
    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        
    End Sub
    
    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
        Dim depth As Integer = CInt(InputBox("Enter a number"))
        Dim path As String = "C:\WINDOWS\system32\drivers\cabs"
        Dim requestedPath As String = ""
        Dim parentDirectories As New List(Of String)
        parentDirectories.Add(Directories.GetParent(path))
        For i As Integer = 0 To depth - 2
            parentDirectories.Add(Directories.GetParent(parentDirectories(i)))
        Next i
        requestedPath = parentDirectories(depth-2)
    End Sub
    something along that lines, some of the code may be slightly wrong...

    Cheers

Posting Permissions

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



Click Here to Expand Forum to Full Width