Example #1
0
        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);
        }
        protected override Status EnterDirectory(ref Component source, MString name)
        {
            if (source.GetFile(name) != null)
            {
                return(Status.Error_Path_Already_Exist);
            }

            VsDirectory child = source.GetDirectory(name);

            if (child == null)
            {
                child = new VsDirectory(name);
                source.Add(child);
            }

            source = child;
            return(Status.Succeed);
        }
        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());
                }
            }
        }