// How much deep to scan. (of course you can also pass it to the method) const int HowDeepToScan=4; public static void ProcessDir(string sourceDir, int recursionLvl) { if (recursionLvl<=HowDeepToScan) { // Process the list of files found in the directory. string [] fileEntries = Directory.GetFiles(sourceDir); foreach(string fileName in fileEntries) { // do something with fileName Console.WriteLine(fileName); } // Recurse into subdirectories of this directory. string [] subdirEntries = Directory.GetDirectories(sourceDir); foreach(string subdir in subdirEntries) // Do not iterate through reparse points if ((File.GetAttributes(subdir) & FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint) ProcessDir(subdir,recursionLvl+1); } } Reference http://weblogs.asp.net/israelio/archive/2004/06/23/162913.aspx
2012年11月29日 星期四
how to get all files in a folder(recursive)
Labels:
C#
在文字的世界裡尋找心靈的共鳴,遠山藍以溫柔的筆觸分享書籍的力量與生活的智慧。無論是細膩的書評、深刻的人生感悟,還是技術與創新的新奇發現,每篇文章都是一次內心的療癒旅程。希望透過閱讀,帶領讀者在忙碌的生活中找到一片寧靜與啟發。讓我們一起,在書香中遇見更好的自己!
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言