Advertisement
Normantas

Finds all images in a directory with fileSize>=minSize

Mar 29th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1.  public static void FindImagesWithSetSize(string directoryInput, string directoryOutput, long minimumFileSize) //FileSize is in Bytes.
  2. {
  3.     List<string> outputPaths = new List<string>();
  4.     foreach (string path in Directory.GetFiles(directoryInput))
  5.     {
  6.         long length = new FileInfo(path).Length;
  7.         if (length >= minimumFileSize) //Finds all valid files
  8.             outputPaths.Add(path);
  9.     }
  10.  
  11.     foreach (string path in outputPaths)
  12.     {
  13.         string outputFile = path.Replace(directoryInput, directoryOutput);
  14.         try
  15.         {
  16.             File.Copy(path, outputFile); //Copies all the valid files to new directory.
  17.         }
  18.         catch
  19.         {
  20.             Console.Error.WriteLine($"{outputFile} with the same name already exists in the output directory");
  21.         }
  22.     }
  23. }
  24.  
  25. /* Anyone is free to use this code*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement