I ran across this code in another post that almost does what I need, but can't figure out how to modify it to look for specific file types, i.e. *.bak, .txt, etc. I'm using Powershell with [System.IO.DirectoryInfo] because, like others have stated, using Get-ChildItem is too slow across the network. I thought it would just be something like $fileEntries = [IO.Directory]::GetFiles("C:\", ".bak"), but it still returns every file in every directory. --PS/.NET newbie
try
{
$fileEntries = [IO.Directory]::GetFiles("C:\")
[System.IO.DirectoryInfo]$directInf = New-Object IO.DirectoryInfo("C:\")
$folders = $directInf.GetDirectories()
}
catch [Exception]
{
$_.Exception.Message
$folders = @()
}
foreach($fileName in $fileEntries)
{
#[Console]::WriteLine($fileName);
}
Remove-Variable -ErrorAction SilentlyContinue -Name fileEntries
foreach($folder in $folders)
{
recurse("C:\" + $folder + "\")
}