Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Listing directories
#1
Hi, I saw this video: <!-- m --><a class="postlink" href="http://www.youtube.com/watch?v=UwGjbPwrMXo">http://www.youtube.com/watch?v=UwGjbPwrMXo</a><!-- m --> to list all files in a directorie, however I need to list all sub directories, like this:

->Main dir
-->file1
-->Sub dir
--->file2

I need the app to list it this way:

file1
Sub dir/file2

How can I do this?
#2
Hello Covert2String - Welcome to the forum!!

Here is a code that should work for you, not sure if it is exactly what you wanted:

Code:
Dim output As String = ""
        Dim dirinfo As New System.IO.DirectoryInfo(My.Application.Info.DirectoryPath)
        Dim allfileinfo() As System.IO.FileInfo = dirinfo.GetFiles("*", IO.SearchOption.AllDirectories)
        For Each item In allfileinfo
            If item.DirectoryName = My.Application.Info.DirectoryPath Then
                output = output + item.Name + vbNewLine
            Else
                output = output + item.DirectoryName + item.Name + vbNewLine
            End If
        Next
My Blog | My Setup | My Videos | Have a wonderful day.
#3
Thanks for the code, but it's not working exactly as I want, the application it's showing the absolute path, like this:


C:\Users\REMOVED\Desktop\list\list\bin\Debug\actlist.vshost.exe
C:\Users\REMOVED\Desktop\list\list\bin\Debug\actlist.vshost.exe
C:\Users\REMOVED\Desktop\list\list\bin\Debug\act\ddlist.xml

I want it only to show act\ddlist or the file if it's not in a sub dir.
#4
Ah okay, well what you can do is use this code...

Code:
Dim output As String = ""
        Dim dirinfo As New System.IO.DirectoryInfo(My.Application.Info.DirectoryPath)
        Dim allfileinfo() As System.IO.FileInfo = dirinfo.GetFiles("*", IO.SearchOption.AllDirectories)
        For Each item In allfileinfo
            If item.DirectoryName = My.Application.Info.DirectoryPath Then
                dim path as string = item.fullname.replace(my.application.info.directorypath, "")
                output = output + path + vbNewLine
            Else
dim path as string = item.fullname.replace(my.application.info.directorypath, "")
                output = output + path + vbNewLine
            End If
        Next

This should work!
My Blog | My Setup | My Videos | Have a wonderful day.
#5
Well, almost there! Idk why, but it writes the last file twice o.O

Edit: Not only the last file but all of them...
#6
Well that could be a problem... Try this code!

Code:
Dim output As String = ""
        Dim dirinfo As New System.IO.DirectoryInfo(My.Application.Info.DirectoryPath)
        Dim allfileinfo() As System.IO.FileInfo = dirinfo.GetFiles("*", IO.SearchOption.AllDirectories)
        For Each item In allfileinfo
                dim path as string = item.fullname.replace(my.application.info.directorypath, "")
                output = output + path + vbNewLine
            
        Next

This should do it!!!
My Blog | My Setup | My Videos | Have a wonderful day.
#7
Not working, it repeats some files :S

Edit: Forget it, my mistake! Thank you! You're a life saver!
#8
Ah, sounds good! I am glad I could help!! Do you fully understand the code?
My Blog | My Setup | My Videos | Have a wonderful day.
#9
Yes, all thanks to you!


Forum Jump:


Users browsing this thread: 1 Guest(s)