Exemple #1
0
        public static void Move(String sourceDirName, String destDirName)
        {
            if (sourceDirName == null)
            {
                throw new ArgumentNullException("sourceDirName");
            }
            if (sourceDirName.Length == 0)
            {
                throw new ArgumentException(SR.Argument_EmptyFileName, "sourceDirName");
            }

            if (destDirName == null)
            {
                throw new ArgumentNullException("destDirName");
            }
            if (destDirName.Length == 0)
            {
                throw new ArgumentException(SR.Argument_EmptyFileName, "destDirName");
            }
            Contract.EndContractBlock();

            String fullsourceDirName = PathHelpers.GetFullPathInternal(sourceDirName);
            String sourcePath        = EnsureTrailingDirectorySeparator(fullsourceDirName);

            int maxDirectoryPath = FileSystem.Current.MaxDirectoryPath;

            if (sourcePath.Length >= maxDirectoryPath)
            {
                throw new PathTooLongException(SR.IO_PathTooLong);
            }

            String fulldestDirName = PathHelpers.GetFullPathInternal(destDirName);
            String destPath        = EnsureTrailingDirectorySeparator(fulldestDirName);

            if (destPath.Length >= maxDirectoryPath)
            {
                throw new PathTooLongException(SR.IO_PathTooLong);
            }

            StringComparison pathComparison = PathInternal.GetComparison();

            if (String.Compare(sourcePath, destPath, pathComparison) == 0)
            {
                throw new IOException(SR.IO_SourceDestMustBeDifferent);
            }

            String sourceRoot      = Path.GetPathRoot(sourcePath);
            String destinationRoot = Path.GetPathRoot(destPath);

            if (String.Compare(sourceRoot, destinationRoot, pathComparison) != 0)
            {
                throw new IOException(SR.IO_SourceDestMustHaveSameRoot);
            }

            FileSystem.Current.MoveDirectory(fullsourceDirName, fulldestDirName);
        }
Exemple #2
0
        public void MoveTo(String destDirName)
        {
            if (destDirName == null)
            {
                throw new ArgumentNullException("destDirName");
            }
            if (destDirName.Length == 0)
            {
                throw new ArgumentException(SR.Argument_EmptyFileName, "destDirName");
            }
            Contract.EndContractBlock();

            String fullDestDirName = PathHelpers.GetFullPathInternal(destDirName);

            if (fullDestDirName[fullDestDirName.Length - 1] != Path.DirectorySeparatorChar)
            {
                fullDestDirName = fullDestDirName + PathHelpers.DirectorySeparatorCharAsString;
            }

            String fullSourcePath;

            if (FullPath.Length > 0 && FullPath[FullPath.Length - 1] == Path.DirectorySeparatorChar)
            {
                fullSourcePath = FullPath;
            }
            else
            {
                fullSourcePath = FullPath + PathHelpers.DirectorySeparatorCharAsString;
            }

            StringComparison pathComparison = PathInternal.GetComparison();

            if (String.Compare(fullSourcePath, fullDestDirName, pathComparison) == 0)
            {
                throw new IOException(SR.IO_SourceDestMustBeDifferent);
            }

            String sourceRoot      = Path.GetPathRoot(fullSourcePath);
            String destinationRoot = Path.GetPathRoot(fullDestDirName);

            if (String.Compare(sourceRoot, destinationRoot, pathComparison) != 0)
            {
                throw new IOException(SR.IO_SourceDestMustHaveSameRoot);
            }

            FileSystem.Current.MoveDirectory(FullPath, fullDestDirName);

            FullPath     = fullDestDirName;
            OriginalPath = destDirName;
            DisplayPath  = GetDisplayName(OriginalPath, FullPath);

            // Flush any cached information about the directory.
            Invalidate();
        }
        [System.Security.SecurityCritical]  // auto-generated
        private DirectoryInfo CreateSubdirectoryHelper(String path)
        {
            Contract.Requires(path != null);

            PathHelpers.ThrowIfEmptyOrRootedPath(path);

            String newDirs  = Path.Combine(FullPath, path);
            String fullPath = Path.GetFullPath(newDirs);

            if (0 != String.Compare(FullPath, 0, fullPath, 0, FullPath.Length, PathInternal.GetComparison()))
            {
                throw new ArgumentException(SR.Format(SR.Argument_InvalidSubPath, path, DisplayPath), "path");
            }

            FileSystem.Current.CreateDirectory(fullPath);

            // Check for read permission to directory we hand back by calling this constructor.
            return(new DirectoryInfo(fullPath));
        }