Results 1 to 14 of 14

Thread: [RESOLVED] FolderBrowserDialog

  1. #1

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Resolved [RESOLVED] FolderBrowserDialog

    Hey

    how can say when the folder is selected (user pressed the ok )
    go and do other thing..
    2 more thing : i need to know all the files name that are in that folder that is selected

    last thing : i know the files now how can i open each of them and read their content ...???

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: FolderBrowserDialog

    Look up My.Computer.FileSystem in MSDN or other tutorials for all the methods you're likely to need.

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

    Re: FolderBrowserDialog

    try this:

    vb Code:
    1. Dim files() As String
    2.  
    3. Dim fbd As New FolderBrowserDialog
    4. If fbd.ShowDialog = DialogResult.OK Then
    5.     files = IO.Directory.GetFiles(fbd.SelectedPath, "*.txt") 'get all text files in selected folder
    6. End If
    7.  
    8. For Each file As String In files
    9.     Debug.Print(IO.File.ReadAllText(file))
    10. Next

  4. #4

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: FolderBrowserDialog

    didnt work when i put it in Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

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

    Re: FolderBrowserDialog

    it definitely works. i tested it. check the output in your immediate window (debug window)

  6. #6

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: FolderBrowserDialog

    i got it work in listbox but its kinda messy..so i need to tell him when u reach to the end of the lenght character go to the new line hows that possible ??? so if i get to the new line i'll do i+=1 and then go to the new file and on and on ....and i need to know the file name too ?!
    Last edited by Pc Monk; Jul 28th, 2012 at 02:38 PM.

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

    Re: FolderBrowserDialog

    instead of io.file.readalltext use:

    io.file.readalllines + the listbox's items.addrange method.

    if you're not sure how to do that post your code + i'll show you how to change it

  8. #8

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: FolderBrowserDialog

    to be honest i dont know how to do it
    the program is going to take a directory which theres full of .php and .tpl files in it ...
    read every php and tpl file line by line
    then sum them all and tell the user that all the php and tpl lines are example of 1000 lines together
    here is what i have that u told me already
    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim files() As String
    
            Dim fbd As New FolderBrowserDialog
            If fbd.ShowDialog = DialogResult.OK Then
                files = IO.Directory.GetFiles(fbd.SelectedPath, "*.txt") 'get all text files in selected folder
            End If
    
            For Each file As String In files
    
                ListBox1.Items.AddRange((IO.File.ReadAllLines(file))
          
            Next
    
        End Sub
    End Class
    i changed it but nothing happend !

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

    Re: FolderBrowserDialog

    you just want a sum of all the line counts of all of the .php and .tpl files in a directory?

  10. #10

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: FolderBrowserDialog

    any programming prefix ..php css tpl txt html xml ...those that u can open them with notepad too ..not prefix like VS and ...
    Last edited by Pc Monk; Jul 28th, 2012 at 03:28 PM.

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

    Re: FolderBrowserDialog

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Dim files As New List(Of String)
    3.  
    4.     Dim fbd As New FolderBrowserDialog
    5.     If fbd.ShowDialog = DialogResult.OK Then
    6.         files.AddRange(IO.Directory.GetFiles(fbd.SelectedPath, "*.php")) 'get all php files in selected folder
    7.         files.AddRange(IO.Directory.GetFiles(fbd.SelectedPath, "*.tpl")) 'get all tpl files in selected folder
    8.         'repeat for all file types
    9.     End If
    10.  
    11.     MsgBox(files.Sum(Function(f) IO.File.ReadAllLines(f).Length))
    12.  
    13. End Sub

  12. #12

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: FolderBrowserDialog

    thanks for that ....the only thing is i have directory into directory ..like template1 theres 10 .php and in the template folder theres a css folder that contain 4 .css file in there but this will only go for root..so how can it go into other directory and count those lines as well

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

    Re: FolderBrowserDialog

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Dim files As New List(Of String)
    3.  
    4.     Dim fbd As New FolderBrowserDialog
    5.     If fbd.ShowDialog = DialogResult.OK Then
    6.         files.AddRange(IO.Directory.GetFiles(fbd.SelectedPath, "*.php", IO.SearchOption.AllDirectories)) 'get all php files in selected folder
    7.         files.AddRange(IO.Directory.GetFiles(fbd.SelectedPath, "*.tpl", IO.SearchOption.AllDirectories)) 'get all tpl files in selected folder
    8.         'repeat for all file types
    9.     End If
    10.  
    11.     MsgBox(files.Sum(Function(f) IO.File.ReadAllLines(f).Length))
    12.  
    13.     'if you want to put all of the filenames in your listbox
    14.     listbox1.items.addrange(Array.ConvertAll(files.ToArray, Function(f) New IO.FileInfo(f)))
    15.  
    16. End Sub

  14. #14

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: FolderBrowserDialog

    thank you so much

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