Guest User

C# App WebDevHobo StackOverflow

a guest
Apr 5th, 2010
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. using System.Windows.Forms;
  2. using System.IO;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. namespace SizeComparer {
  7.     public partial class Form1 : Form {
  8.  
  9.         private string origFolder = string.Empty;
  10.         private string shrunkFolder = string.Empty;
  11.         private List<string> origFiles;
  12.         private List<string> shrunkFiles;
  13.  
  14.         private FileInfo shrunkFileInfo;
  15.         private FileInfo origFileInfo;
  16.         private DirectoryInfo dirOrig;
  17.         private DirectoryInfo dirShrunk;
  18.  
  19.         public Form1() {
  20.             InitializeComponent();
  21.             this.folderBrowseOriginal.ShowNewFolderButton = false;
  22.             this.origFiles = new List<string>();
  23.             this.shrunkFiles = new List<string>();
  24.         }
  25.  
  26.         private void originalButton_Click(object sender, System.EventArgs e) {
  27.             DialogResult dr = this.folderBrowseOriginal.ShowDialog();
  28.             if(DialogResult.OK == dr) {
  29.                 this.origFolder = this.folderBrowseOriginal.SelectedPath;
  30.                 this.dirOrig = new DirectoryInfo(this.origFolder);
  31.                 this.fillList(this.dirOrig, this.origFiles);
  32.             }
  33.         }
  34.  
  35.         private void shrunkButton_Click(object sender, System.EventArgs e) {
  36.             DialogResult dr = this.folderBrowseShrunk.ShowDialog();
  37.             if(DialogResult.OK == dr) {
  38.                 this.shrunkFolder = this.folderBrowseShrunk.SelectedPath;
  39.                 this.dirShrunk = new DirectoryInfo(this.shrunkFolder);
  40.                 this.fillList(this.dirShrunk, this.shrunkFiles);
  41.             }
  42.         }
  43.  
  44.         private void fillList(DirectoryInfo dir, List<string> list) {
  45.             foreach(FileInfo fi in dir.GetFiles("*.jpg")) {
  46.                 list.Add(fi.FullName);
  47.             }
  48.             foreach(FileInfo fi in dir.GetFiles("*.png")) {
  49.                 list.Add(fi.FullName);
  50.             }
  51.             foreach(FileInfo fi in dir.GetFiles("*.gif")) {
  52.                 list.Add(fi.FullName);
  53.             }
  54.         }
  55.  
  56.         private void copyButton_Click(object sender, System.EventArgs e) {
  57.             int fileIndex = 0;
  58.             string origFile = string.Empty;
  59.  
  60.             foreach(string shrunk in this.shrunkFiles) {
  61.                 fileIndex = this.origFiles.IndexOf(shrunk.Replace("\\Test",""));
  62.  
  63.                 if(fileIndex == -1) {
  64.                     continue;
  65.                 } else {
  66.                     origFile = this.origFiles[fileIndex];
  67.                 }
  68.  
  69.                 this.shrunkFileInfo = new FileInfo(shrunk);
  70.                 this.origFileInfo = new FileInfo(origFile);
  71.  
  72.                 if(this.shrunkFileInfo.Length < this.origFileInfo.Length) {
  73.                     File.Replace(shrunk, origFile, @"C:\Temp\tempfile");
  74.                 }
  75.             }
  76.         }
  77.  
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment