Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

Commit e3c56c6

Browse files
committed
fix(search)
1 parent 897498f commit e3c56c6

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

Services/DiskManager/DiskManager.cs

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,63 @@ public List<string> GetMusicFiles()
116116
List<string> FindFiles()
117117
{
118118
var files = new List<string>();
119-
foreach (var foundFiles in from path in paths
120-
from ext in MusicFilesExtensions
121-
select Directory.EnumerateFiles(path, $"*{ext}", SearchOption.AllDirectories))
122-
files.AddRange(foundFiles);
119+
120+
foreach (var path in paths)
121+
{
122+
foreach (var ext in MusicFilesExtensions)
123+
{
124+
try
125+
{
126+
var foundFiles = Directory.EnumerateFiles(path, $"*{ext}", SearchOption.TopDirectoryOnly);
127+
files.AddRange(foundFiles);
128+
129+
if (SearchOption.AllDirectories == SearchOption.AllDirectories)
130+
{
131+
TraverseSubdirectories(path, ext, files);
132+
}
133+
}
134+
catch (UnauthorizedAccessException)
135+
{
136+
}
137+
catch (DirectoryNotFoundException)
138+
{
139+
}
140+
}
141+
}
142+
123143
return files;
124144
}
125145
}
126146

147+
private static void TraverseSubdirectories(string rootPath, string extension, List<string> files)
148+
{
149+
try
150+
{
151+
var directories = Directory.EnumerateDirectories(rootPath);
152+
153+
foreach (var directory in directories)
154+
{
155+
try
156+
{
157+
var foundFiles =
158+
Directory.EnumerateFiles(directory, $"*{extension}", SearchOption.TopDirectoryOnly);
159+
files.AddRange(foundFiles);
160+
TraverseSubdirectories(directory, extension, files);
161+
}
162+
catch (UnauthorizedAccessException)
163+
{
164+
}
165+
catch (DirectoryNotFoundException)
166+
{
167+
}
168+
}
169+
}
170+
catch (UnauthorizedAccessException)
171+
{
172+
173+
}
174+
}
175+
127176
public List<string> GetMusicFiles(string path)
128177
{
129178
var result = new List<string>();

0 commit comments

Comments
 (0)