Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static List<FileInfo> files = new List<FileInfo>(); // List that will hold the files and subfiles in path
- static List<DirectoryInfo> folders = new List<DirectoryInfo>(); // List that hold direcotries that cannot be accessed
- static void FullDirList(DirectoryInfo rootDir, string searchPattern)
- {
- // Console.WriteLine("Directory {0}", dir.FullName);
- // list the files
- try
- {
- foreach (FileInfo f in rootDir.GetFiles(searchPattern))
- {
- //Console.WriteLine("File {0}", f.FullName);
- files.Add(f);
- }
- }
- catch
- {
- Console.WriteLine("Directory {0} \n could not be accessed!!!!", rootDir.FullName);
- return; // We alredy got an error trying to access dir so dont try to access it again
- }
- // process each directory
- // If I have been able to see the files in the directory I should also be able
- // to look at its directories so I dont think I should place this in a try catch block
- foreach (DirectoryInfo d in rootDir.GetDirectories())
- {
- folders.Add(d);
- FullDirList(d, searchPattern);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement