I have a powershell script that I currently use when I am searching for files. I am trying to port it to c# but cannot seem to get an equivalent working.
The Powershell script is:
$drives= gwmi Win32_LogicalDisk -Filter "DriveType=3 or DriveType=4"|select Name|foreach-object {$_.Name + "\"}
$files=@(
"*.txt","*.docx","*.doc"
)
foreach ($drive in $drives){
$filenames = Get-ChildItem $drive -Recurse -include $files -erroraction silentlycontinue | Where {($_.FullName -notlike *Windows*) -and ($_.FullName -notlike "*Microsoft*") -and ($_.FullName -notlike "*Temp*") -and ($_.FullName -notlike "*Google*") -and ($_.FullName -notlike "*Mozilla*") -and ($_.FullName -notlike "*Recycle*") -and ($_.FullName -notlike "*tmp*")} |where-object{!($_.PSIsContainter)} | % {$_.FullName}
I have this c# code to search through directories but I am not sure how to omit directories and cannot find nay examples online
var extensions = new List<string> { ".txt", ".doc" };
string[] files = Directory.GetFiles(sDir, "*.*", SearchOption.AllDirectories)
.Where(f => extensions.IndexOf(Path.GetExtension(f)) >= 0).ToArray();
Thanks