Advertisement
tankcr

Untitled

May 22nd, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. static List<FileInfo> files = new List<FileInfo>();  // List that will hold the files and subfiles in path
  2.         static List<DirectoryInfo> folders = new List<DirectoryInfo>(); // List that hold direcotries that cannot be accessed
  3.         static void FullDirList(DirectoryInfo rootDir, string searchPattern)
  4.         {
  5.             // Console.WriteLine("Directory {0}", dir.FullName);
  6.             // list the files
  7.             try
  8.             {
  9.                 foreach (FileInfo f in rootDir.GetFiles(searchPattern))
  10.                 {
  11.                     //Console.WriteLine("File {0}", f.FullName);
  12.                     files.Add(f);
  13.                 }
  14.             }
  15.             catch
  16.             {
  17.                 Console.WriteLine("Directory {0}  \n could not be accessed!!!!", rootDir.FullName);
  18.                 return;  // We alredy got an error trying to access dir so dont try to access it again
  19.             }
  20.  
  21.             // process each directory
  22.             // If I have been able to see the files in the directory I should also be able
  23.             // to look at its directories so I dont think I should place this in a try catch block
  24.             foreach (DirectoryInfo d in rootDir.GetDirectories())
  25.             {
  26.                 folders.Add(d);
  27.                 FullDirList(d, searchPattern);
  28.             }
  29.  
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement