/// <summary> /// Creates the directory. /// </summary> /// <param name="dirPath">The directory path.</param> /// <exception cref="ArgumentException"><paramref name="dirPath"/> is null or empty.</exception> /// <exception cref="UnauthorizedAccessException">Unauthorized access.</exception> public static void CreateDirectory(string dirPath, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(dirPath)) { throw new ArgumentException("Value cannot be null or empty", "dirPath"); } RetryStrategy.TryExecute(() => CreateDirectoryInternal(dirPath), cancellationToken); }
/// <summary> /// Deletes file. /// </summary> /// <param name="filePath">The file path.</param> /// <param name="cancellationToken"></param> /// <exception cref="ArgumentException"><paramref name="filePath"/> is null or empty.</exception> /// <exception cref="FileNotFoundException"><paramref name="filePath"/> doesn't exist.</exception> /// <exception cref="UnauthorizedAccessException">Unauthorized access.</exception> public static void Delete(string filePath, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentException("Value cannot be null or empty", "filePath"); } if (!File.Exists(filePath)) { throw new ArgumentException("File must exist", "filePath"); } RetryStrategy.TryExecute(() => DeleteInternal(filePath), cancellationToken); }
/// <summary> /// Creates the directory. /// </summary> /// <param name="dirPath">The directory path.</param> /// <param name="recursive">if set to <c>true</c> then directory content is also removed recursively.</param> /// <exception cref="ArgumentException"><paramref name="dirPath" /> is null or empty.</exception> /// <exception cref="DirectoryNotFoundException"><paramref name="dirPath" /> doesn't exist.</exception> /// <exception cref="UnauthorizedAccessException">Unauthorized access.</exception> public static void Delete(string dirPath, CancellationToken cancellationToken, bool recursive = false) { if (string.IsNullOrEmpty(dirPath)) { throw new ArgumentException("Value cannot be null or empty", "dirPath)"); } if (!Directory.Exists(dirPath)) { throw new ArgumentException("Directory must exist", "dirPath"); } RetryStrategy.TryExecute(() => DeleteInternal(dirPath, recursive), cancellationToken); }
/// <summary> /// Copies file from <paramref name="sourceFilePath" /> to <paramref name="destinationFilePath" />. /// </summary> /// <param name="sourceFilePath">The source file path.</param> /// <param name="destinationFilePath">The destination file path.</param> /// <param name="overwrite">if set to <c>true</c> and destination file exists then it is overwritten.</param> /// <param name="cancellationToken"></param> /// <exception cref="ArgumentException"><paramref name="sourceFilePath"/> is null or empty.</exception> /// <exception cref="ArgumentException"><paramref name="destinationFilePath"/> is null or empty.</exception> /// <exception cref="FileNotFoundException"><paramref name="sourceFilePath"/> doesn't exist.</exception> /// <exception cref="DirectoryNotFoundException"><paramref name="destinationFilePath"/> parent directory doesn't exist.</exception> /// <exception cref="UnauthorizedAccessException">Unauthorized access.</exception> public static void Copy(string sourceFilePath, string destinationFilePath, bool overwrite, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(sourceFilePath)) { throw new ArgumentException("Value cannot be null or empty", "sourceFilePath"); } if (string.IsNullOrEmpty(destinationFilePath)) { throw new ArgumentException("Value cannot be null or empty", "destinationFilePath"); } if (!File.Exists(sourceFilePath)) { throw new ArgumentException("Source file must exist", "sourceFilePath"); } if (!Directory.Exists(Path.GetDirectoryName(destinationFilePath))) { throw new ArgumentException("Parent directory of destination must exist", "destinationFilePath"); } RetryStrategy.TryExecute(() => CopyInternal(sourceFilePath, destinationFilePath, overwrite), cancellationToken); }