Exemplo n.º 1
0
        private void OK_Click(object sender, RoutedEventArgs e)
        {
            bool?  isCopy = IsCopyRadio.IsChecked;
            string tem;

            if (isCopy.Value)
            {
                tem = "复制";
            }
            else
            {
                tem = "更名或者移动";
            }
            int successCount          = 0;
            int falseCount            = 0;
            var fileReplaceNameModels = filePagerPage.GetAllList <FileReplaceNameModel>();

            if (fileReplaceNameModels.Count > 0)
            {
                if (MessageBoxCustom.MessageBoxShow("你将" + tem + fileReplaceNameModels.Count + " 个文件"))
                {
                    foreach (FileReplaceNameModel model in fileReplaceNameModels)
                    {
                        WaitFormCustom.ShowCustom();
                        string path     = model.FilePath;
                        string saveName = model.NewFileName;
                        string saveDir  = Path.GetDirectoryName(saveName);
                        if (saveDir == "")
                        {
                            model.Success = false;
                            continue;
                        }
                        if (!Utils.CheckDirExists(saveDir))
                        {
                            Directory.CreateDirectory(saveDir);
                        }
                        if (Utils.CheckFileExists(path))
                        {
                            if (isCopy.Value)
                            {
                                File.Copy(path, saveName, true);
                            }
                            else
                            {
                                File.Move(path, saveName);
                            }
                            successCount++;
                            model.Success = true;
                        }
                        else
                        {
                            model.Success = false;
                            falseCount++;
                        }
                    }
                    WaitFormCustom.CloseWaitForm("成功:" + successCount + " 个文件,失败:" + falseCount + " 个文件");
                }
            }
        }