Skip to content

Commit 4968d8e

Browse files
author
David Kline
authored
Merge pull request #7290 from davidkline-ms/findAssets
Remove alternate implementation of FindFilesInAssets
2 parents 9507028 + 87cd0e7 commit 4968d8e

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

Assets/MixedRealityToolkit/Utilities/Editor/FileUtilities.cs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,25 @@ public static class FileUtilities
1717
/// Locates the files that match the specified name within the Assets folder structure.
1818
/// </summary>
1919
/// <param name="fileName">The name of the file to locate (ex: "TestFile.asmdef")</param>
20-
/// <param name="searchFullFileSystem">If true, searches the full application data path. If false, only searches Unity's known asset database.</param>
2120
/// <returns>Array of FileInfo objects representing the located file(s).</returns>
22-
public static FileInfo[] FindFilesInAssets(string fileName, bool searchFullFileSystem = false)
21+
public static FileInfo[] FindFilesInAssets(string fileName)
2322
{
24-
if (searchFullFileSystem)
25-
{
26-
DirectoryInfo root = new DirectoryInfo(Application.dataPath);
27-
return FindFiles(fileName, root);
28-
}
29-
else
23+
// FindAssets doesn't take a file extension
24+
string[] assetGuids = AssetDatabase.FindAssets(Path.GetFileNameWithoutExtension(fileName));
25+
26+
List<FileInfo> fileInfos = new List<FileInfo>();
27+
for (int i = 0; i < assetGuids.Length; i++)
3028
{
31-
// FindAssets doesn't take a file extension
32-
string[] assetGuids = AssetDatabase.FindAssets(Path.GetFileNameWithoutExtension(fileName));
33-
List<FileInfo> fileInfos = new List<FileInfo>();
34-
for (int i = 0; i < assetGuids.Length; i++)
29+
string assetPath = AssetDatabase.GUIDToAssetPath(assetGuids[i]);
30+
// Since this is an asset search without extension, some filenames may contain parts of other filenames.
31+
// Therefore, double check that the path actually contains the filename with extension.
32+
if (assetPath.Contains(fileName))
3533
{
36-
string assetPath = AssetDatabase.GUIDToAssetPath(assetGuids[i]);
37-
// Since this is an asset search without extension, some filenames may contain parts of other filenames.
38-
// Therefore, double check that the path actually contains the filename with extension.
39-
if (assetPath.Contains(fileName))
40-
{
41-
fileInfos.Add(new FileInfo(assetPath));
42-
}
34+
fileInfos.Add(new FileInfo(assetPath));
4335
}
44-
return fileInfos.ToArray();
4536
}
37+
38+
return fileInfos.ToArray();
4639
}
4740

4841
/// <summary>

0 commit comments

Comments
 (0)