puzzled
puzzled

Reputation: 57

LINQ accessing drives

I would like to know if LINQ can be used to access the drives on my computer. I have some data stored in the drives and am performing a search on it. Can LINQ be used for this? Thanks!

Upvotes: 2

Views: 76

Answers (2)

Jason Down
Jason Down

Reputation: 22171

You can start by looking at LINQ and File Directories on MSDN.

Based on your comment (looking for .dcm files), take a look at this example on MSDN. It looks for .txt files, so it should be close enough to what you need to get started.

Upvotes: 6

Michael Petrotta
Michael Petrotta

Reputation: 60942

LINQ is commonly used to operate over IEnumerable collections, and many methods in the System.IO namespace return IEnumerables. So, yes.

For example:

var dirInfo = new DirectoryInfo("C:\\");
var matches = from infos in dirInfo.EnumerateFiles()
              where infos.CreationTime > DateTime.Now - TimeSpan.FromDays(1)
              select infos.Name;

Upvotes: 4

Related Questions