Created
December 2, 2023 15:54
-
-
Save gudezhi/2015a16e7e8c13ea5f81776d6d9d5cf2 to your computer and use it in GitHub Desktop.
[object Object]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Show-Tree { | |
param( | |
[string]$RootPath, | |
[string[]]$ExcludeFolders | |
) | |
$indentation = " " | |
$folderStack = New-Object 'string[]' 100 # 增加数组的初始大小 | |
function Print-Line($line, $depth) { | |
if($depth -lt $folderStack.Length) { | |
"$($folderStack[0..($depth-1)] -join '')$line" | |
} else { | |
Write-Warning "Depth of directory exceeds folderStack array size." | |
} | |
} | |
function Get-Tree($path, $depth) { | |
if($depth -ge $folderStack.Length) { | |
Write-Warning "Depth of directory exceeds folderStack array size." | |
return | |
} | |
Get-ChildItem -Path $path -Directory -Force | ForEach-Object { | |
if($ExcludeFolders -contains $_.Name) { return } | |
$folderStack[$depth] = $indentation | |
Write-Host (Print-Line "+---$($_.Name)" $depth) | |
Get-Tree $_.FullName ($depth + 1) | |
$folderStack[$depth] = $null | |
} | |
Get-ChildItem -Path $path -File -Force | ForEach-Object { | |
Write-Host (Print-Line "|---$($_.Name)" $depth) | |
} | |
} | |
Write-Host (Print-Line $RootPath 0) | |
Get-Tree $RootPath 1 | |
} | |
# 使用这个函数 | |
Show-Tree -RootPath "d:\zheteng\upwork_tariq\leads_emailflow_ai" -ExcludeFolders @("__pycache__", ".git", ".mypy_cache") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment