To achieve the task of displaying a tree of the current folder, showing all folders and files with .mod and .work extensions using the Windows tree command, you can use the following command in the Command Prompt:
tree /f /a | findstr /i /r /c:"$" /c:"\.mod$" /c:"\.work$"
However, the above command won't work as expected because findstr will only show lines that match the specified patterns, and it won't preserve the tree structure properly if a directory doesn't contain a matching file.
A better approach is to use PowerShell to achieve this. Here's a PowerShell command that will display all directories and only the files with .mod and .work extensions:
Get-ChildItem -Path .\ -Recurse -Force | Where-Object { !$_.PSIsContainer -and ($_.Extension -eq ".mod" -or $_.Extension -eq ".work") } | ForEach-Object { Write-Host $_.FullName }
Get-ChildItem -Path .\ -Recurse -Force | Where-Object { $_.PSIsContainer } | ForEach-Object { Write-Host $_.FullName }
However, the above PowerShell commands will list the files and directories separately. To get a tree-like structure, you can use the following PowerShell script:
function Show-Tree($path = ".") {
Get-ChildItem -Path $path | ForEach-Object {
if ($_.PSIsContainer) {
Write-Host ($_.FullName) -ForegroundColor Cyan
Show-Tree -path $_.FullName
} else {
if ($_.Extension -eq ".mod" -or $_.Extension -eq ".work") {
Write-Host ($_.FullName) -ForegroundColor Yellow
}
}
}
}
Show-Tree
This script will recursively list all directories and files with .mod and .work extensions in a tree-like structure. Directories will be displayed in Cyan, and the matching files will be displayed in Yellow.
To directly use the tree command and filter the output, you can use the following command:
tree /f /a > all.txt
type all.txt | findstr /i /r /c:"$[a-zA-Z0-9\\\. ]*$" /c:"\.mod$" /c:"\.work$"
This will first save the entire tree to a file named all.txt, and then it will display all lines that are either directory names or file names ending with .mod or .work. However, this is still not perfect as it doesn't preserve the original tree structure indentation properly.
To get a more accurate tree representation, consider using a dedicated tool or a more complex PowerShell script.