コード例 #1
0
 private void txtbPath1_TextChanged(object sender, TextChangedEventArgs e)
 {
     //加载文件列表
     if (Directory.Exists(txtbPath1.Text))
     {
         btnGoal.Visibility = Visibility.Visible;
         Thread td = new Thread((obj) =>
         {
             string path           = obj.ToString();
             DirectoryInfo dirinfo = new DirectoryInfo(path);
             if (dirinfo.GetFiles().Length < 1)
             {
                 return;
             }
             foreach (var item in dirinfo.GetFiles())
             {
                 Fileinfo_tf finfo = new Fileinfo_tf();
                 finfo.Name        = item.Name;
                 finfo.AlterTime   = item.LastWriteTime.ToString("yyyy/MM/dd-HH:mm:ss");
                 if (item.Length < 1024)
                 {
                     finfo.Size = item.Length.ToString() + " B";
                 }
                 else if (item.Length < 1024L * 1024L)
                 {
                     long size  = item.Length / 1024;
                     finfo.Size = string.Format("{0} KB", size);
                 }
                 else if (item.Length < 1024L * 1024L * 1024L)
                 {
                     long size  = item.Length / (1024L * 1024L);
                     finfo.Size = string.Format("{0} MB", size);
                 }
                 else
                 {
                     double size = item.Length / (1024.00 * 1024.00 * 1024.00);
                     finfo.Size  = string.Format("{0:0.00} GB", size);
                 }
                 finfo.LastWriteTime = item.LastWriteTime;
                 finfo.Length        = item.Length;
                 filelist.Add(finfo);
                 fileskvp.Add(finfo.Name, finfo);
             }
             this.Dispatcher.Invoke(new Action(() => { datagrid.ItemsSource = filelist; }));
         });
         td.IsBackground = true;
         td.Start(txtbPath1.Text);
     }
     else
     {
         btnGoal.Visibility = Visibility.Hidden;
     }
 }
コード例 #2
0
 private void Contrast()
 {
     if (Directory.Exists(txtbPath2.Text))
     {
         //在对比过程中隐藏模式选择框
         comboxMode.Visibility = Visibility.Hidden;
         ThreadPool.QueueUserWorkItem(new WaitCallback((obj) =>
         {
             string path           = obj.ToString();
             DirectoryInfo dirinfo = new DirectoryInfo(path);
             foreach (var item in filelist)
             {
                 item.NoCopy = false;
             }
             if (dirinfo.GetFiles().Length < 1)
             {
                 this.Dispatcher.Invoke(new Action(() => { comboxMode.Visibility = Visibility.Visible; }));
                 return;
             }
             foreach (var item in dirinfo.GetFiles())
             {
                 //如果存在同名文件则判断
                 if (fileskvp.ContainsKey(item.Name))
                 {
                     //获取原信息文件
                     Fileinfo_tf fi = fileskvp[item.Name];
                     if (combSelectedIndex == 1)
                     {
                         //目标文件大于等于原文件则不拷贝
                         if (fi.Length <= item.Length)
                         {
                             filelist.Remove(fi);
                             fi.NoCopy = true;
                             filelist.Add(fi);
                         }
                     }
                     else
                     {
                         //目标文件修改时间在后则不拷贝
                         if (fi.LastWriteTime <= item.LastWriteTime)
                         {
                             filelist.Remove(fi);
                             fi.NoCopy = true;
                             filelist.Add(fi);
                         }
                     }
                 }
             }
             this.Dispatcher.Invoke(new Action(() => { comboxMode.Visibility = Visibility.Visible; }));
         }), txtbPath2.Text);
     }
 }