Esempio n. 1
0
 /// <exception cref="ArgumentNullException"><paramref name="env"/> or <paramref name="path"/> is
 ///  <see langword="null"/></exception>
 /// <exception cref="InvalidOperationException">Cannot clean directory when <paramref name="env.FS"/> is null.
 /// </exception>
 public static void Clean(IFileSystemEnvironment env, DirectoryPath path)
 {
     Clean(env, path, null);
 }
 /// <summary>
 /// Copies an existing file to a new location.
 /// </summary>
 /// <param name="env">The context.</param>
 /// <param name="filePath">The file path.</param>
 /// <param name="targetDirectoryPath">The target directory path.</param>
 /// <example>
 /// <code>
 /// CopyFileToDirectory("test.txt", "./targetdir");
 /// </code>
 /// </example>
 /// <exception cref="ArgumentNullException"><paramref name="env"/> or <paramref name="filePath"/>
 ///  or <paramref name="targetDirectoryPath"/> is <see langword="null"/></exception>
 /// <exception cref="FileNotFoundException">The file does not exist.</exception>
 /// <exception cref="InvalidOperationException">The target directory does not exist.</exception>
 public static void CopyFileToDirectory(this IFileSystemEnvironment env,
                                        FilePath filePath,
                                        DirectoryPath targetDirectoryPath)
 {
     FileCopier.CopyFileToDirectory(env, filePath, targetDirectoryPath);
 }
 /// <summary>
 /// Copies all files matching the provided pattern to a new location.
 /// </summary>
 /// <param name="env">The context.</param>
 /// <param name="pattern">The pattern.</param>
 /// <param name="targetDirectoryPath">The target directory path.</param>
 /// <example>
 /// <code>
 /// CopyFiles("Cake.*", "./publish");
 /// </code>
 /// </example>
 /// <exception cref="ArgumentNullException"><paramref name="env"/> or <paramref name="pattern"/>
 ///  or <paramref name="targetDirectoryPath"/> is <see langword="null"/></exception>
 /// <exception cref="FileNotFoundException">The file does not exist.</exception>
 /// <exception cref="InvalidOperationException">The target directory does not exist.</exception>
 public static void CopyFiles(this IFileSystemEnvironment env, string pattern,
                              DirectoryPath targetDirectoryPath)
 {
     FileCopier.CopyFiles(env, pattern, targetDirectoryPath);
 }
 /// <summary>
 /// Moves existing files matching the specified pattern to a new location.
 /// </summary>
 /// <param name="env">The context.</param>
 /// <param name="pattern">The pattern.</param>
 /// <param name="targetDirectoryPath">The target directory path.</param>
 /// <example>
 /// <code>
 /// MoveFiles("./publish/Cake.*", "./destination");
 /// </code>
 /// </example>
 /// <exception cref="ArgumentNullException"><paramref name="env"/> or <paramref name="pattern"/>
 ///  or <paramref name="targetDirectoryPath"/> is <see langword="null"/></exception>
 /// <exception cref="FileNotFoundException">The target directory do not exist.</exception>
 public static void MoveFiles(this IFileSystemEnvironment env, string pattern,
                              DirectoryPath targetDirectoryPath)
 {
     FileMover.MoveFiles(env, pattern, targetDirectoryPath);
 }
 /// <summary>
 /// Moves existing files to a new location.
 /// </summary>
 /// <param name="env">The context.</param>
 /// <param name="filePaths">The file paths.</param>
 /// <param name="targetDirectoryPath">The target directory path.</param>
 /// <example>
 /// <code>
 /// var files = GetFiles("./publish/Cake.*");
 /// MoveFiles(files, "destination");
 /// </code>
 /// </example>
 /// <exception cref="ArgumentNullException"><paramref name="env"/> or <paramref name="filePaths"/>
 ///  or <paramref name="targetDirectoryPath"/> is <see langword="null"/></exception>
 /// <exception cref="FileNotFoundException">The target directory do not exist.</exception>
 /// <exception cref="InvalidOperationException">The directory <paramref name="targetDirectoryPath"/>.FullPath
 ///  do not exist.</exception>
 public static void MoveFiles(this IFileSystemEnvironment env, IEnumerable <FilePath> filePaths,
                              DirectoryPath targetDirectoryPath)
 {
     FileMover.MoveFiles(env, filePaths, targetDirectoryPath);
 }
Esempio n. 6
0
 /// <summary>
 /// Get the relative path to another directory.
 /// </summary>
 /// <param name="to">The target directory path.</param>
 /// <returns>A <see cref="DirectoryPath"/>.</returns>
 public DirectoryPath GetRelativePath(DirectoryPath to)
 {
     return(GetDirectory().GetRelativePath(to));
 }
 /// <summary>
 /// Moves an existing file to a new location.
 /// </summary>
 /// <param name="env">The context.</param>
 /// <param name="filePath">The file path.</param>
 /// <param name="targetDirectoryPath">The target directory path.</param>
 /// <example>
 /// <code>
 /// MoveFileToDirectory("test.txt", "./targetdir");
 /// </code>
 /// </example>
 /// <exception cref="ArgumentNullException"><paramref name="env"/> or <paramref name="filePath"/>
 ///  or <paramref name="targetDirectoryPath"/> is <see langword="null"/></exception>
 /// <exception cref="FileNotFoundException">The target directory do not exist..</exception>
 public static void MoveFileToDirectory(this IFileSystemEnvironment env, FilePath filePath,
                                        DirectoryPath targetDirectoryPath)
 {
     FileMover.MoveFileToDirectory(env, filePath, targetDirectoryPath);
 }
Esempio n. 8
0
        /// <summary>
        /// Copies the contents of a directory to the specified location.
        /// </summary>
        /// <example>
        /// <code>
        /// CopyDirectory("source_path", "destination_path");
        /// </code>
        /// </example>
        /// <param name="env">The context.</param>
        /// <param name="source">The source directory path.</param>
        /// <param name="destination">The destination directory path.</param>
        /// <exception cref="ArgumentNullException"><paramref name="env"/> or <paramref name="source"/>
        ///  or <paramref name="destination"/> is <see langword="null"/></exception>
        /// <exception cref="InvalidOperationException">Source directory does not exist or could not be found.</exception>
        public static void CopyDirectory(this IFileSystemEnvironment env, DirectoryPath source,
                                         DirectoryPath destination)
        {
            if (env == null)
            {
                throw new ArgumentNullException(nameof(env));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            if (env.FS == null)
            {
                throw new InvalidOperationException(
                          $"Cannot check if directory exists when {nameof(env)}.{nameof(env.FS)} is null");
            }

            if (source.IsRelative)
            {
                source = source.MakeAbsolute(env);
            }

            // Get the subdirectories for the specified directory.
            var sourceDir = env.FS.GetDirectory(source);

            if (!sourceDir.Exists)
            {
                throw new InvalidOperationException("Source directory does not exist or could not be found: "
                                                    + source.FullPath);
            }

            var dirs = sourceDir.GetDirectories("*", SearchScope.Current);

            var destinationDir = env.FS.GetDirectory(destination);

            if (!destinationDir.Exists)
            {
                destinationDir.Create();
            }

            // Get the files in the directory and copy them to the new location.
            var files = sourceDir.GetFiles("*", SearchScope.Current);

            foreach (var file in files)
            {
                var temppath = destinationDir.Path.CombineWithFilePath(file.Path.GetFilename());
                file.Copy(temppath, true);
            }

            // Copy all of the subdirectories
            foreach (var subdir in dirs)
            {
                var temppath = destination.Combine(subdir.Path.GetDirectoryName());
                CopyDirectory(env, subdir.Path, temppath);
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Creates the specified directory.
 /// </summary>
 /// <example>
 /// <code>
 /// CreateDirectory("publish");
 /// </code>
 /// </example>
 /// <param name="env">The context.</param>
 /// <param name="path">The directory path.</param>
 /// <exception cref="ArgumentNullException"><paramref name="env"/> or <paramref name="path"/> is
 ///  <see langword="null"/></exception>
 /// <exception cref="InvalidOperationException">Cannot create directory when <paramref name="env.FS"/> is null.
 /// </exception>
 public static void CreateDirectory(this IFileSystemEnvironment env, DirectoryPath path)
 {
     DirectoryCreator.Create(env, path);
 }
Esempio n. 10
0
 /// <summary>
 /// Cleans the specified directory.
 /// </summary>
 /// <example>
 /// <code>
 /// CleanDirectory("./src/Cake.Common/obj", fileSystemInfo=>!fileSystemInfo.Hidden);
 /// </code>
 /// </example>
 /// <param name="env">The context.</param>
 /// <param name="path">The directory path.</param>
 /// <param name="predicate">Predicate used to determine which files/directories should get deleted.</param>
 /// <exception cref="ArgumentNullException"><paramref name="env"/> or <paramref name="path"/>
 ///  or <paramref name="predicate"/> is <see langword="null"/></exception>
 /// <exception cref="InvalidOperationException">Cannot clean directory when <paramref name="env.FS"/> is null.
 /// </exception>
 public static void CleanDirectory(this IFileSystemEnvironment env, DirectoryPath path,
                                   Func <IFileSystemInfo, bool> predicate)
 {
     DirectoryCleaner.Clean(env, path, predicate);
 }
Esempio n. 11
0
 /// <summary>
 /// Cleans the specified directory.
 /// </summary>
 /// <example>
 /// <code>
 /// CleanDirectory("./src/Cake.Common/obj");
 /// </code>
 /// </example>
 /// <param name="env">The context.</param>
 /// <param name="path">The directory path.</param>
 /// <exception cref="ArgumentNullException">env or path is
 ///  <see langword="null"/></exception>
 /// <exception cref="InvalidOperationException">Cannot clean directory when <paramref name="env.FS"/> is null.
 /// </exception>
 public static void CleanDirectory(this IFileSystemEnvironment env, DirectoryPath path)
 {
     DirectoryCleaner.Clean(env, path);
 }
Esempio n. 12
0
 /// <summary>
 /// Deletes the specified directory.
 /// </summary>
 /// <example>
 /// <code>
 /// DeleteDirectory("./be/gone", recursive:true);
 /// </code>
 /// </example>
 /// <param name="env">The context.</param>
 /// <param name="path">The directory path.</param>
 /// <param name="recursive">Will perform a recursive delete if set to <c>true</c>.</param>
 /// <exception cref="System.IO.IOException">The directory <paramref name="path.FullPath"/> does not exist. -or-
 ///  Cannot delete directory <paramref name="path.FullPath"/> without recursion since it's not empty.
 /// </exception>
 /// <exception cref="ArgumentNullException"><paramref name="env"/> or <paramref name="path "/>is
 ///  <see langword="null"/></exception>
 /// <exception cref="InvalidOperationException">Cannot delete directory when <paramref name="env.FS"/> is null.
 /// </exception>
 public static void DeleteDirectory(this IFileSystemEnvironment env, DirectoryPath path,
                                    bool recursive = false)
 {
     DirectoryDeleter.Delete(env, path, recursive);
 }