Facebook
From Stefan, 5 Days ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 25
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace intChanger
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         BackgroundWorker _bgwCopyOperation = new BackgroundWorker();
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.             _bgwCopyOperation.WorkerReportsProgress = true;
  21.             _bgwCopyOperation.WorkerSupportsCancellation = true;
  22.         }
  23.  
  24.         private void Form1_Load(object sender, EventArgs e)
  25.         {
  26.  
  27.         }
  28.  
  29.         string Dirr;
  30.         string Dirr2;
  31.         int no = 0;
  32.         int Count = 0;
  33.         int Count2 = 0;
  34.         private void _bgwCopyOperation_DoWork(object sender, DoWorkEventArgs e, string sourceDirName, string destDirName, bool copySubDirs)
  35.         {
  36.             if (no == 0)
  37.             {
  38.                 no = 1;
  39.                 Dirr = sourceDirName;
  40.                 Dirr2 = destDirName;
  41.                 Count = Directory.GetFiles(Dirr, "*.*", SearchOption.AllDirectories).Length;
  42.                 Count = 100 / Count;
  43.             }
  44.            
  45.             // Get the subdirectories for the specified directory.
  46.             DirectoryInfo dir = new DirectoryInfo(sourceDirName);
  47.  
  48.             if (!dir.Exists)
  49.             {
  50.                 throw new DirectoryNotFoundException(
  51.                     "Source directory does not exist or could not be found: "
  52.                     + sourceDirName);
  53.             }
  54.  
  55.             DirectoryInfo[] dirs = dir.GetDirectories();
  56.             // If the destination directory doesn't exist, create it.
  57.             if (!Directory.Exists(destDirName))
  58.             {
  59.                 Directory.CreateDirectory(destDirName);
  60.             }
  61.  
  62.             // Get the files in the directory and copy them to the new location.
  63.             FileInfo[] files = dir.GetFiles();
  64.             foreach (FileInfo file in files)
  65.             {
  66.                 string temppath = Path.Combine(destDirName, file.Name);
  67.                 file.CopyTo(temppath, false);
  68.                 Count2 = Count2 + 1;
  69.  
  70.                 //Update progressbar here
  71.                 _bgwCopyOperation.ReportProgress(Count2 * Count);
  72.             }
  73.  
  74.             // If copying subdirectories, copy them and their contents to new location.
  75.             if (copySubDirs)
  76.             {
  77.                 foreach (DirectoryInfo subdir in dirs)
  78.                 {
  79.                     string temppath = Path.Combine(destDirName, subdir.Name);
  80.                     //Foo((object)new object[] { (object)"1", (object)"2" }));
  81.                     _bgwCopyOperation.RunWorkerAsync((object)new object[] { (object)subdir.FullName, (object)temppath, (object)copySubDirs });
  82.                     //_bgwCopyOperation.RunWorkerAsync(subdir.FullName, temppath, copySubDirs);
  83.                 }
  84.             }
  85.         }
  86.  
  87.         private void button1_Click(object sender, EventArgs e)
  88.         {
  89.             if (_bgwCopyOperation.IsBusy != true)
  90.             {
  91.                 // Start the asynchronous operation.
  92.                 _bgwCopyOperation.RunWorkerAsync((object)new object[] { (object)@"C:\Users\Stefan\Downloads\Portable Python 2.7.15 Basic (x64)\Portable Python 2.7.15 x64", (object)@"C:\Users\Stefan\Documents\Backuppers_Backups\Portable Python 2.7.15 x64", (object)true });
  93.             }
  94.  
  95.         }
  96.  
  97.         private void _bgwCopyOperation_ProgressChanged(object sender, ProgressChangedEventArgs e)
  98.         {
  99.             progressBar1.Value = e.ProgressPercentage;
  100.         }
  101.     }
  102. }
  103.