Esempio n. 1
0
        public NPath Move(NPath dest)
        {
            ThrowIfNotInitialized();
            ThrowIfNotInitialized(dest);

            if (IsRoot)
            {
                throw new NotSupportedException("Move is not supported on a root level directory because it would be dangerous:" + ToString());
            }

            if (dest.IsRelative)
            {
                return(Move(Parent.Combine(dest)));
            }

            if (dest.DirectoryExists())
            {
                return(Move(dest.Combine(FileName)));
            }

            if (FileExists())
            {
                dest.DeleteIfExists();
                dest.EnsureParentDirectoryExists();
                FSWrapper.FileMove(this, dest);
                return(dest);
            }

            if (DirectoryExists())
            {
                FSWrapper.DirectoryMove(this, dest);
                return(dest);
            }

            throw new ArgumentException("Move() called on a path that doesn't exist: " + ToProcessDirectory().ToString());
        }