Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hirs my simple code

For Each founddirectory As String In My.Computer.FileSystem.GetFiles(folderbrowserdialog1.selectedpath,
Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.*")

ListBox1.Items.Add(founddirectory)

but when i search drive c theres an error can you help me to fix this code? sorry if im not good in english

What I have tried:

ive tried only vb can you help me
Posted
Updated 24-Jan-17 18:16pm

1 solution

'The following code loops through all the files and folders in c:\drive.

Imports System.IO

Module Module1
    Sub Main()
        PrintFiles("c:\")
    End Sub

    Private Sub PrintFiles(ByVal root As String)
        'Write the folder name
        Console.WriteLine("Folder: " + root + Environment.NewLine)

        'Write all the files in this folder
        For Each fileName As String In Directory.GetFiles(root)
            Console.WriteLine("File: " + fileName + Environment.NewLine)
        Next

        'If there are directories in this folder process them
        For Each foundDir As String In Directory.GetDirectories(root)
            Try
                PrintFiles(foundDir)
            Catch
                'In case of some exceptions
            End Try
        Next
    End Sub
End Module
 
Share this answer
 
v2
Comments
bryanjaysena@yahoo.com 31-Jan-17 9:27am    
i have error in module module1 :(
sonymon mishra 6-Feb-17 2:08am    
Hi, is it working now?
bryanjaysena@yahoo.com 24-Feb-17 6:22am    
do you have facebook account ? can i add you sir
sonymon mishra 2-Feb-17 4:00am    
What is the error.
Try using the PrintFiles method only in your project.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900