I want to list all files names exist under folder in hard drive with vb.net , and i don't know how.First ,i choose a folder with folderbrowser component, next,i list all files
Here is my code (only for choose a folder)
dossier_disque.ShowDialog()
txt_folder.Text = dossier_disque.SelectedPath
for list all files , i tried to use for each , but it's not correct
my code when i tried to list file
Dim files() As String = Directory.GetFiles(txt_folder.Text)
For Each a In CStr(files.Count)
folder_hard.Rows.Add(Directory.GetFiles(txt_folder.Text))
Next
folder_hard is a grid name txt_folder is a name of a folder path
With this code , the result , i can see only the first file twice in grid
There is a problem with your for each loop: CStr() converts values into strings. So your for loop is looping through each char in the string of the number of files in the files array. So change it to:
Then a will be each file name in the files array. If you want to add each to your grid you need to change that line to :
So this should work: