예제 #1
0
 private void btn_run_Click(object sender, EventArgs e)
 {
     new Thread(() =>
     {
         try
         {
             setEnable(false);
             _setlog("源文件夹:" + tb_s.Text);
             _setlog("目标文件夹:" + tb_t.Text);
             var allfile = IOExtension.GetAllFiles(tb_s.Text);
             if (allfile == null || allfile.Count == 0)
             {
                 _setlog("源文件夹为空....,请重新选择");
                 setEnable(true);
                 return;
             }
             var allfilet = IOExtension.GetAllFiles(tb_t.Text);
             if (allfilet != null && allfilet.Count != 0)
             {
                 _setlog("目标文件夹必须为空....,请重新选择");
                 setEnable(true);
                 return;
             }
             _setlog($"获取到文件{allfile.Count}个,共计大小{ IOExtension.CountSize(allfile.Sum(a => a.Length)) }");
             _setlog("清除目标路径");
             IOExtension.DeleteFile(tb_t.Text);
             _setlog("开始复制文件");
             int i = copy(tb_s.Text.Trim(), tb_t.Text.Trim());
             if (i != 0)
             {
                 if (i == 1223)
                 {
                     IOExtension.DeleteFile(tb_t.Text);
                     _setlog("用户取消,删除目标文件夹文件");
                 }
                 else
                 {
                     _setlog(ShellFileOperation.GetErrorString(i));
                 }
                 setEnable(true);
                 return;
             }
             _setlog("复制完成,删除原始文件");
             IOExtension.DeleteFile(tb_s.Text);
             _setlog("开始设置目录");
             RunCmd cmd  = new RunCmd();
             cmd.Output += (str) =>
             {
                 if (str == "c:\\>")
                 {
                     _setlog($"完成,请通过\"{tb_s.Text}\"检查文件是否存在");
                     setEnable(true);
                 }
             };
             cmd.Run($"mklink /j \"{tb_s.Text}\" \"{tb_t.Text}\"");
         }
         catch (Exception ex)
         {
             _setlog(ex.Message);
             setEnable(true);
         }
     }).Start();
 }