11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
4+ using System . Collections . Generic ;
45using System . IO ;
56using UnityEditor ;
67using UnityEngine ;
@@ -13,14 +14,35 @@ namespace Microsoft.MixedReality.Toolkit.Utilities.Editor
1314 public static class FileUtilities
1415 {
1516 /// <summary>
16- /// Locates the files that match the specified name within the Assets folder (application data path) structure.
17+ /// Locates the files that match the specified name within the Assets folder structure.
1718 /// </summary>
1819 /// <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>
1921 /// <returns>Array of FileInfo objects representing the located file(s).</returns>
20- public static FileInfo [ ] FindFilesInAssets ( string fileName )
22+ public static FileInfo [ ] FindFilesInAssets ( string fileName , bool searchFullFileSystem = false )
2123 {
22- DirectoryInfo root = new DirectoryInfo ( Application . dataPath ) ;
23- return FindFiles ( fileName , root ) ;
24+ if ( searchFullFileSystem )
25+ {
26+ DirectoryInfo root = new DirectoryInfo ( Application . dataPath ) ;
27+ return FindFiles ( fileName , root ) ;
28+ }
29+ else
30+ {
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 ++ )
35+ {
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+ }
43+ }
44+ return fileInfos . ToArray ( ) ;
45+ }
2446 }
2547
2648 /// <summary>
0 commit comments