Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
hi guys, i wanna to list all files, subfolder, files inside subfolder at partiular folder exp: D:\testfol and add in listbox. is it possible??
if possible can provide some example??
thanks,
Posted 30-Dec-12 15:20pm
Edited 30-Dec-12 15:29pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

WPF has nothing to do with the file system. Your question is a C# question. In the System.IO namespace is a Directory class, it has static GetFiles and GetDirectories methods, which you can use to recurse through the file system
  Permalink  
Comments
lailailaihou at 30-Dec-12 21:30pm
   
i see, if use GetFiles and GetDirectory need to use foreach loop??
Christian Graus at 30-Dec-12 21:35pm
   
I didn't say anything about a loop. I said you can recurse if you want to go through several levels.
lailailaihou at 30-Dec-12 21:36pm
   
i got this but only list the files and folder in D:\testfol
if want to list out all files and folder inside D:\testfol\test1
but folder selected path is D:\testfol is it possible??
DirectoryInfo di = new DirectoryInfo(@fol.SelectedPath);
FileInfo[] fi = di.GetFiles();
foreach (FileInfo f in fi)
{
if (f.Attributes.ToString().Contains(FileAttributes.Hidden.ToString()))
{
listresult.Items.Add(f.FullName);
}
}
foreach(DirectoryInfo d in di.GetDirectories())
if (d.Attributes.ToString().Contains("Hidden"))
{
listresult.Items.Add(d.FullName);
}
Christian Graus at 30-Dec-12 21:40pm
   
Yes, this is called 'recursion'. Search this site for articles on recursion, basically your method takes a path as a parameter and keeps calling itself as it goes down the tree.
lailailaihou at 30-Dec-12 21:42pm
   
i see, so this called recursion.
ok i will search about this in this site thank you for information.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can use the code below
 
foreach (System.IO.FileInfo fi in new System.IO.DirectoryInfo("D:\\testfol").GetFiles("*.*", System.IO.SearchOption.AllDirectories)
             {
// do something
             }
  Permalink  
v2
Comments
lailailaihou at 3-Jan-13 4:10am
   
thank you it work for me...

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

  Print Answers RSS
0 CPallini 365
1 Sergey Alexandrovich Kryukov 252
2 OriginalGriff 165
3 George Jonsson 159
4 Richard MacCutchan 110
0 OriginalGriff 6,344
1 Sergey Alexandrovich Kryukov 5,860
2 CPallini 5,125
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100