Skip to content

Instantly share code, notes, and snippets.

@PartTimeLegend
Created November 13, 2014 20:46
Show Gist options
  • Save PartTimeLegend/a941bb756b9d58d6877b to your computer and use it in GitHub Desktop.
Save PartTimeLegend/a941bb756b9d58d6877b to your computer and use it in GitHub Desktop.
Find all .xls files in C#
public IList<Documents> FindDocuments()
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
IList<Documents> documentsList = new List<Documents>();
foreach (DriveInfo d in allDrives)
{
foreach (var file in Directory.GetFiles(d.ToString(), "*.xls", SearchOption.AllDirectories))
{
Documents documents = new Documents();
documents.FilePath = file;
documentsList.Add(documents);
}
}
return documentsList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment