Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Files.Shared/Helpers/FileExtensionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.IO;
using System.Linq;

namespace Files.Shared.Helpers
Expand All @@ -22,7 +23,12 @@ public static bool HasExtension(string? filePathToCheck, params string[] extensi
if (string.IsNullOrWhiteSpace(filePathToCheck))
return false;

return extensions.Any(ext => filePathToCheck.EndsWith(ext, StringComparison.OrdinalIgnoreCase));
// Don't check folder paths to avoid issues
// https://github.com/files-community/Files/issues/17094
if (Directory.Exists(filePathToCheck))
return false;

return extensions.Any(ext => Path.GetExtension(filePathToCheck).Equals(ext, StringComparison.OrdinalIgnoreCase));
}

/// <summary>
Expand Down Expand Up @@ -54,7 +60,7 @@ public static bool IsAudioFile(string? fileExtensionToCheck)
{
return HasExtension(fileExtensionToCheck, ".mp3", ".m4a", ".wav", ".wma", ".aac", ".adt", ".adts", ".cda", ".flac");
}

/// <summary>
/// Check if the file extension is a video file.
/// </summary>
Expand Down Expand Up @@ -213,7 +219,7 @@ public static bool IsVhdFile(string? fileExtensionToCheck)
{
return HasExtension(fileExtensionToCheck, ".vhd", ".vhdx");
}

/// <summary>
/// Check if the file extension is a screen saver file.
/// </summary>
Expand Down Expand Up @@ -256,7 +262,7 @@ public static bool IsScriptFile(string? filePathToCheck)
{
return HasExtension(filePathToCheck, ".py", ".ahk");
}

/// <summary>
/// Check if the file extension is a system file.
/// </summary>
Expand Down
Loading