C#: How to get files recursively without a recursion

Whenever i had to get all the files from a directory and its subdirectories recursively, i wrote my own little recursive method. But there’s a much smoother way to do this:

string[] files = Directory.GetFiles(yourdirectory, "*.*", SearchOption.AllDirectories);

No big deal, just a common search pattern and an option flag – that’s it! 🙂

Advertisements
C#: How to get files recursively without a recursion

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s