$filePath = "D:\dwg"; $dwg = @(Get-ChildItem -Recurse -Path $filePath | Where-Object { $_.Extension -eq ".dwg" }); if ($dwg.length -eq 0) { write-host "no files found" -foregroundcolor "Red"; } else { foreach ($file in $dwg) { $name = $file.name; $directory = $file.DirectoryName; write-host "$directory\$name" -foregroundcolor "Red"; write-output "$directory\$name" | out-file -append -filepath D:\output.txt -encoding ASCII } }