Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Windows.Forms;
- using System.IO;
- using System.Collections.Generic;
- namespace SizeComparer {
- public partial class Form1 : Form {
- private string origFolder = string.Empty;
- private string shrunkFolder = string.Empty;
- private List<string> origFiles;
- private List<string> shrunkFiles;
- private FileInfo shrunkFileInfo;
- private FileInfo origFileInfo;
- private DirectoryInfo dirOrig;
- private DirectoryInfo dirShrunk;
- public Form1() {
- InitializeComponent();
- this.folderBrowseOriginal.ShowNewFolderButton = false;
- this.origFiles = new List<string>();
- this.shrunkFiles = new List<string>();
- }
- private void originalButton_Click(object sender, System.EventArgs e) {
- DialogResult dr = this.folderBrowseOriginal.ShowDialog();
- if(DialogResult.OK == dr) {
- this.origFolder = this.folderBrowseOriginal.SelectedPath;
- this.dirOrig = new DirectoryInfo(this.origFolder);
- this.fillList(this.dirOrig, this.origFiles);
- }
- }
- private void shrunkButton_Click(object sender, System.EventArgs e) {
- DialogResult dr = this.folderBrowseShrunk.ShowDialog();
- if(DialogResult.OK == dr) {
- this.shrunkFolder = this.folderBrowseShrunk.SelectedPath;
- this.dirShrunk = new DirectoryInfo(this.shrunkFolder);
- this.fillList(this.dirShrunk, this.shrunkFiles);
- }
- }
- private void fillList(DirectoryInfo dir, List<string> list) {
- foreach(FileInfo fi in dir.GetFiles("*.jpg")) {
- list.Add(fi.FullName);
- }
- foreach(FileInfo fi in dir.GetFiles("*.png")) {
- list.Add(fi.FullName);
- }
- foreach(FileInfo fi in dir.GetFiles("*.gif")) {
- list.Add(fi.FullName);
- }
- }
- private void copyButton_Click(object sender, System.EventArgs e) {
- int fileIndex = 0;
- string origFile = string.Empty;
- foreach(string shrunk in this.shrunkFiles) {
- fileIndex = this.origFiles.IndexOf(shrunk.Replace("\\Test",""));
- if(fileIndex == -1) {
- continue;
- } else {
- origFile = this.origFiles[fileIndex];
- }
- this.shrunkFileInfo = new FileInfo(shrunk);
- this.origFileInfo = new FileInfo(origFile);
- if(this.shrunkFileInfo.Length < this.origFileInfo.Length) {
- File.Replace(shrunk, origFile, @"C:\Temp\tempfile");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment