public void CopyAll(FileInfo[] sourceFileInfos, Component targetDir) { string result = ""; foreach (FileInfo fi in sourceFileInfos) { Console.WriteLine(fi.FullName); Component file = targetDir.GetChild(fi.Name); if (file != null) { if (file.IsDirectory()) { Console.WriteLine("拒绝访问。"); continue; } else { if (Logger.ChooseDialogYNA(ref result, "覆盖 {0} 吗?", fi.Name)) { file.Remove(); } else { continue; } } } file = new VsFile(fi.Name.Remove(fi.Name.Length - fi.Extension.Length, fi.Extension.Length), fi.Extension); (file as VsFile).Read(fi.FullName); targetDir.Add(file); } }
public override void Excute() { if (_path == "") { Logger.Log(Status.Error_Commond_Format); return; } MString fileName; Status status = CheckPath(ref _path, out _tempTarget, out fileName, false); if (status != Status.Succeed) { Logger.Log(status); return; } else if (fileName != "*") { Logger.Log(Status.Error_Path_Not_Found); return; } if (_tempTarget != null) { Component cursorTemp = VsDiskMoniter.Instance.Cursor; while (cursorTemp != null) { if ((cursorTemp != _tempTarget)) { cursorTemp = cursorTemp.parent; } else { Logger.Log(Status.Error_IO); return; } } if (_tempTarget.childs.Count > 0) { if (!_formatS) { Logger.Log(Status.Dir_Not_Empty); return; } else { if (!Logger.ChooseDialogYN("是否确认")) { return; } } } _tempTarget.Remove(); } }
private Status ExcuteByPattern(Component target, string pattern) { if (pattern == "*") //删除目录下所有文件 { for (int i = 0; i < target.childs.Count; i++) { Component child = target.childs[i]; if (child.IsDirectory()) { continue; } child.Remove(); } } else if (pattern.StartsWith("*.")) //删除指定后缀名的文件 { string matchStr = pattern.Substring(2); if (nameRegex.IsMatch(matchStr)) { return(Status.Error_Path_Format); } for (int i = 0; i < target.childs.Count; i++) { Component child = target.childs[i]; if (child.IsDirectory()) { continue; } if (child.GetName().EndsWith(matchStr)) { child.Remove(); i--; } } } else //删除单个文件 { if (nameRegex.IsMatch(pattern)) { return(Status.Error_Path_Format); } VsFile file = target.GetFile(pattern); if (file != null) { file.Remove(); } } return(Status.Succeed); }
public void CopyAllWithChangeExName(FileInfo[] sourceFileInfos, Component targetDir, string lastDestPath) { string result = ""; string exName = lastDestPath.Substring(1); if (exName == ".") { exName = ""; } foreach (FileInfo fi in sourceFileInfos) { Console.WriteLine(fi.FullName); string name = fi.Name.Remove(fi.Name.Length - fi.Extension.Length, fi.Extension.Length) + exName; Component file = targetDir.GetChild(name); if (file != null) { if (file.IsDirectory()) { Console.WriteLine("拒绝访问。"); continue; } else { if (Logger.ChooseDialogYNA(ref result, "覆盖 {0} 吗?", fi.Name)) { file.Remove(); } else { continue; } } } string newExName = ""; if (name.LastIndexOf('.') != -1) { newExName = name.Substring(name.LastIndexOf('.'), name.Length - name.LastIndexOf('.')); } string newName = name.Remove(name.Length - newExName.Length, newExName.Length); file = new VsFile(newName, newExName); (file as VsFile).Read(fi.FullName); targetDir.Add(file); } }
public void CopyWithChangeNameAndExName(FileInfo[] sourceFileInfos, Component targetDir, string lastDestPath) { string result = ""; string exName = ""; if (lastDestPath.LastIndexOf('.') != -1) { exName = lastDestPath.Substring(lastDestPath.LastIndexOf('.'), lastDestPath.Length - lastDestPath.LastIndexOf('.')); } string name = lastDestPath.Remove(lastDestPath.Length - exName.Length, exName.Length); Component file = targetDir.GetChild(lastDestPath); if (file != null) { if (file.IsDirectory()) { Console.WriteLine("拒绝访问。"); return; } else { if (Logger.ChooseDialogYNA(ref result, "覆盖 {0} 吗?", name)) { file.Remove(); } else { return; } } } file = new VsFile(name, exName); foreach (FileInfo fi in sourceFileInfos) { Console.WriteLine(fi.FullName); (file as VsFile).Read(fi.FullName); } targetDir.Add(file); }