Skip to content

Commit

Permalink
[nuget-skip] Added overwrite parameter to TryMoveFile
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaoticz committed May 25, 2024
1 parent 04ea83a commit b74166e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>2.3.1</VersionPrefix>
<VersionPrefix>2.3.2</VersionPrefix>
<Authors>Kotz</Authors>
<Copyright>Copyright © Kotz 2022</Copyright>
<PackageProjectUrl>https://github.com/Kaoticz/Kotz.Utilities</PackageProjectUrl>
Expand Down
10 changes: 6 additions & 4 deletions Kotz.Extensions/KotzUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,21 +328,23 @@ public static bool TryDeleteDirectory(string directoryUri, bool isRecursive = tr
/// </summary>
/// <param name="source">The path to the source file or directory.</param>
/// <param name="destination">The path to the destination file or directory.</param>
/// <param name="overwriteFile">Determines whether the destination file should be overwritten if it already exists.</param>
/// <returns><see langword="true"/> if the file system object got successfully moved, <see langword="false"/> otherwise.</returns>
/// <exception cref="ArgumentException" />
/// <exception cref="ArgumentNullException" />
public static bool TryMoveFSO(string source, string destination)
=> TryMoveFile(source, destination) || TryMoveDirectory(source, destination);
public static bool TryMoveFSO(string source, string destination, bool overwriteFile = false)
=> TryMoveFile(source, destination, overwriteFile) || TryMoveDirectory(source, destination);

/// <summary>
/// Safely moves a file.
/// </summary>
/// <param name="source">The path to the source file.</param>
/// <param name="destination">The path to the destination file.</param>
/// <param name="overwrite">Determines whether the destination file should be overwritten if it already exists.</param>
/// <returns><see langword="true"/> if the file got successfully moved, <see langword="false"/> otherwise.</returns>
/// <exception cref="ArgumentException" />
/// <exception cref="ArgumentNullException" />
public static bool TryMoveFile(string source, string destination)
public static bool TryMoveFile(string source, string destination, bool overwrite = false)
{
ArgumentException.ThrowIfNullOrEmpty(source, nameof(source));
ArgumentException.ThrowIfNullOrEmpty(destination, nameof(destination));
Expand All @@ -358,7 +360,7 @@ public static bool TryMoveFile(string source, string destination)
if (!directoryUri.Exists)
directoryUri.Create();

File.Move(source, destination);
File.Move(source, destination, overwrite);

return true;
}
Expand Down

0 comments on commit b74166e

Please sign in to comment.