var files = from file in my.Computer.FileSystem.GetFiles(CurDir()) orderby file select file;
var files = from file in Directory.GetFiles(Environment.CurrentDirectory)
orderby file
select file;
Edit: use the code from Gabe's answer if you're using .Net 4.0; it's better for the reasons he mentions. Use this if you're using 3.5.
This is an alternative in newer versions of .Net:
var files = from file in Directory.EnumerateFiles(Environment.CurrentDirectory)
orderby file
select file;
Generally speaking, it is preferable to use EnumerateFiles instead of GetFiles because it does not create a whole array of strings before returning. This not only saves the creation of the array, but allows you to start processing as soon as the first filename is read rather than having to wait until the last one is read.
You can think of GetFiles() as EnumerateFiles().ToArray().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With