diff --git a/SabreTools.Helper/Objects/Dat/DatItem.cs b/SabreTools.Helper/Objects/Dat/DatItem.cs
index 1bf5e7b0..281abe3a 100644
--- a/SabreTools.Helper/Objects/Dat/DatItem.cs
+++ b/SabreTools.Helper/Objects/Dat/DatItem.cs
@@ -809,11 +809,11 @@ namespace SabreTools.Helper
{
if ((x.Type == ItemType.Rom || x.Type == ItemType.Disk) && (y.Type == ItemType.Rom || y.Type == ItemType.Disk))
{
- if (Path.GetDirectoryName(x.Name) == Path.GetDirectoryName(y.Name))
+ if (Path.GetDirectoryName(Style.RemovePathUnsafeCharacters(x.Name)) == Path.GetDirectoryName(Style.RemovePathUnsafeCharacters(y.Name)))
{
- return nc.Compare(Path.GetFileName(x.Name), Path.GetFileName(y.Name));
+ return nc.Compare(Path.GetFileName(Style.RemovePathUnsafeCharacters(x.Name)), Path.GetFileName(Style.RemovePathUnsafeCharacters(y.Name)));
}
- return nc.Compare(Path.GetDirectoryName(x.Name), Path.GetDirectoryName(y.Name));
+ return nc.Compare(Path.GetDirectoryName(Style.RemovePathUnsafeCharacters(x.Name)), Path.GetDirectoryName(Style.RemovePathUnsafeCharacters(y.Name)));
}
else if ((x.Type == ItemType.Rom || x.Type == ItemType.Disk) && (y.Type != ItemType.Rom && y.Type != ItemType.Disk))
{
diff --git a/SabreTools.Helper/Tools/Style.cs b/SabreTools.Helper/Tools/Style.cs
index b7f6694c..711d1a37 100644
--- a/SabreTools.Helper/Tools/Style.cs
+++ b/SabreTools.Helper/Tools/Style.cs
@@ -429,6 +429,18 @@ namespace SabreTools.Helper
return (s.Any(c => c > 255));
}
+ ///
+ /// Remove all chars that are considered path unsafe
+ ///
+ /// Input string to clean
+ /// Cleaned string
+ public static string RemovePathUnsafeCharacters(string s)
+ {
+ List invalidPath = Path.GetInvalidPathChars().ToList();
+ List invalidName = Path.GetInvalidFileNameChars().ToList();
+ return new string(s.Where(c => !invalidPath.Contains(c) && !invalidName.Contains(c)).ToArray());
+ }
+
#endregion
#region Externally sourced methods