Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi,

I was trying to list all the files and folders in C drive in listbox using C#, but couldn't able to succeed.

Could you please help me on this below task,

A button click to list down all the files and folders present on C drive in "ListBox".
Posted
Comments
Sergey Alexandrovich Kryukov 3-Jun-14 17:15pm    
"Couldn't able to succeed"? It's not informative. What have you tried so far?
The problem is way too simple, with one little twist: you have to ignore the file system object the user is not permitted to see.
—SA
DamithSL 3-Jun-14 22:29pm    

This code may help you:
C#
String[] dirs = System.IO.Directory.GetDirectories("C:\\");
int i;
for (i = 0; i < dirs.Length; i++)
{
    listBox1.Items.Add(dirs[i]);
}
String[] files = System.IO.Directory.GetFiles("C:\\");
for (i = 0; i < files.Length; i++)
{
    listBox1.Items.Add(files[i]);
}
 
Share this answer
 
Comments
abhicoolhot 4-Jun-14 17:02pm    
Thanks a lot for your guidance... I got an output
Member 12941431 20-Jan-17 23:32pm    
how this code is used in windows store using c#
See this[^] video.

/ravi
 
Share this answer
 

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