/// <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(IFileSystemEnvironment env, FilePath filePath, DirectoryPath targetDirectoryPath) { if (env == null) { throw new ArgumentNullException(nameof(env)); } if (filePath == null) { throw new ArgumentNullException(nameof(filePath)); } if (targetDirectoryPath == null) { throw new ArgumentNullException(nameof(targetDirectoryPath)); } MoveFile(env, filePath, targetDirectoryPath.GetFilePath(filePath)); }
/// <exception cref="ArgumentNullException"><paramref name="env"/> or <paramref name="filePaths"/> or /// <paramref name="targetDirectoryPath"/>is <see langword="null"/></exception> /// <exception cref="InvalidOperationException">The directory <paramref name="targetDirectoryPath.FullPath"/> /// do not exist.</exception> /// <exception cref="FileNotFoundException">The target directory do not exist.</exception> public static void MoveFiles(this IFileSystemEnvironment env, IEnumerable <FilePath> filePaths, DirectoryPath targetDirectoryPath) { if (env == null) { throw new ArgumentNullException(nameof(env)); } if (filePaths == null) { throw new ArgumentNullException(nameof(filePaths)); } if (targetDirectoryPath == null) { throw new ArgumentNullException(nameof(targetDirectoryPath)); } if (env.FS == null) { throw new InvalidOperationException( $"Cannot move files when {nameof(env)}.{nameof(env.FS)} is null"); } targetDirectoryPath = targetDirectoryPath.MakeAbsolute(env); // Make sure the target directory exist. if (!env.FS.Exists(targetDirectoryPath)) { throw new InvalidOperationException($"The directory '{targetDirectoryPath.FullPath}' do not exist."); } // Iterate all files and copy them. foreach (var filePath in filePaths) { MoveFile(env, filePath, targetDirectoryPath.GetFilePath(filePath)); } }