Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. public static void FindAllImages(string root)
  2. {
  3.     Queue<string> folders = new Queue<string>();
  4.     List<string> files = new List<string>();
  5.  
  6.     folders.Enqueue(root);
  7.     while (folders.Count != 0)
  8.     {
  9.         string currentFolder = folders.Dequeue();
  10.  
  11.         // this checks are not tested
  12.         if (filepath.Contains(":/Windows/")) currentFolder = folders.Dequeue();
  13.         if (filepath.Contains(":/Users/") &&
  14.             filepath.Contains(":/AppData/")) currentFolder = folders.Dequeue();
  15.  
  16.         string[] filesInCurrent = null;
  17.         try
  18.         {
  19.             filesInCurrent = Directory.GetFiles(currentFolder, "*.*");
  20.         }
  21.         // Ignore this exceptions
  22.         catch (UnauthorizedAccessException) { }
  23.         catch (PathTooLongException) { }
  24.                
  25.         foreach (string f in filesInCurrent)
  26.             if (MyLib.IsSupported(f)) files.Add(f);
  27.  
  28.         try
  29.         {
  30.             string[] foldersInCurrent = Directory.GetDirectories(currentFolder);
  31.  
  32.             foreach (string _current in foldersInCurrent)
  33.                 folders.Enqueue(_current);
  34.         }
  35.         // Ignore this exceptions
  36.         catch (UnauthorizedAccessException) { }
  37.         catch (PathTooLongException) { }
  38.         catch (DirectoryNotFoundException) { }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement