views:

181

answers:

1

I want to search a directory for all files that match a certain pattern. Surprisingly, I have not had to do this since vb6 (Dir)... I'm sure things have changed since then!

-Thanks

+9  A: 

use SearchOption.AllDirectories parameter:

using System.IO;

Directory.GetFiles(@"C:\", "*.mp3", SearchOption.AllDirectories);
lubos hasko
yes, things have changed since Dir in VB6, the System.IO.SearchOption.AllDirectories means you don't need to recurse the directories yourself anymore.
Hamish Smith
@Hamish But you might still want to manually recurse directories to avoid/handle UnauthorizedAccessExceptions.
Mark Hurd