Exemplo n.º 1
0
        public void ChangeDirectory(DirectoryMove move, string path = null)
        {
            switch (move)
            {
            case DirectoryMove.Back:
                var backDir = CurrentDirectory.Parent;
                ChangeDirectory(backDir);
                break;

            case DirectoryMove.ToRoot:
                var root = Path.GetPathRoot(CurrentDirectoryPath);
                ChangeDirectory(new DirectoryInfo(root));
                break;

            case DirectoryMove.Inner when path is not null:
                var next = Path.Combine(CurrentDirectoryPath, path);
                if (!Path.IsPathFullyQualified(next))
                {
                    throw ExceptionsFactory.PathNotExist(next);
                }
                ChangeDirectory(next);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(move), move, null);
            }

            OnDirectoryChanged?.Invoke();
        }
Exemplo n.º 2
0
        public void CopyFile(string from, string to)
        {
            from = RebasePath(from);
            to   = RebasePath(to);

            if (!File.Exists(from))
            {
                throw ExceptionsFactory.PathNotExist(from);
            }
            if (File.Exists(to))
            {
                while (true)
                {
                    var response = _messenger.Confirm("Output file already exist, rewrite it? (y,n): ");
                    if (!response)
                    {
                        throw ExceptionsFactory.SamePathAlreadyExist(to, nameof(to));
                    }
                    break;
                }
                File.Copy(from, to, true);
            }

            var copyDirectory = Path.GetDirectoryName(to);

            if (!Directory.Exists(copyDirectory))
            {
                Directory.CreateDirectory(copyDirectory);
            }
            File.Copy(from, to);
        }
Exemplo n.º 3
0
        public void CopyDirectory(string from, string to)
        {
            from = RebasePath(from);
            to   = RebasePath(to);

            if (!Directory.Exists(from))
            {
                throw ExceptionsFactory.PathNotExist(from);
            }
            if (!Directory.Exists(to))
            {
                Directory.CreateDirectory(to);
            }
            Directory.Move(from, to);
        }