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!
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.
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;
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