Skip to content

Commit

Permalink
Added DeleteFile method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaex committed May 3, 2022
1 parent 855ddd6 commit 23061aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
43 changes: 26 additions & 17 deletions ShareX.HelpersLib/Helpers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,32 @@ public static string RenameFile(string filePath, string newFileName)
return filePath;
}

public static bool DeleteFile(string filePath, bool sendToRecycleBin = false)
{
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
{
try
{
if (sendToRecycleBin)
{
FileSystem.DeleteFile(filePath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
}
else
{
File.Delete(filePath);
}

return true;
}
catch (Exception e)
{
DebugHelper.WriteException(e);
}
}

return false;
}

public static string BackupFileWeekly(string filePath, string destinationFolder)
{
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
Expand Down Expand Up @@ -1689,23 +1715,6 @@ public static Task ForEachAsync<T>(IEnumerable<T> inputEnumerable, Func<T, Task>
return Task.WhenAll(tasks);
}

public static bool SendFileToRecycleBin(string filePath)
{
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
{
try
{
FileSystem.DeleteFile(filePath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
return true;
}
catch
{
}
}

return false;
}

public static void LockCursorToWindow(Form form)
{
form.Activated += (sender, e) => Cursor.Clip = form.Bounds;
Expand Down
2 changes: 1 addition & 1 deletion ShareX/UploadInfoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public void DeleteFiles()
{
foreach (string filePath in SelectedItems.Select(x => x.Info.FilePath))
{
Helpers.SendFileToRecycleBin(filePath);
Helpers.DeleteFile(filePath, true);
}
}
}
Expand Down

0 comments on commit 23061aa

Please sign in to comment.