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); } }
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 override void Excute() { if (_path == "") { _target = VsDiskMoniter.Instance.Cursor; } else { MString fileName; Status status = CheckPath(ref _path, out _target, out fileName, false); if (status != Status.Succeed) { Logger.Log(status); return; } else if (fileName != "*") { var file = _target.GetFile(fileName); if (file == null) { Logger.Log(Status.Error_Path_Not_Found); return; } _target = file; } } if (_target != null) { if (_target.IsDirectory()) { ShowDirectoryInfos(_target); } else { Console.WriteLine(" " + _target.parent.GetPath() + " 的目录\n"); Console.WriteLine(_target.GetChangeTime() + (_target as VsFile).GetFileSizeString() + _target.GetName()); } } }
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); }